Jyson FAQ

Why use Jyson instead of a java codec?

The advantage of using jyson instead of a java codec is that jyson produces a hierarchy of jython objects, namely org.python.core.PyObject . These objects are custom designed to be manipulated by jython code.

On the other hand, a java codec might produce a java.util.Map or java.util.List or other java objects, which it is possible to manipulate from jython code, but would not be natural jython objects.

Consider the following

Jython 2.5b2+ (trunk, Mar 8 2009, 20:40:45)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.5.0_17
Type "help", "copyright", "credits" or "license" for more information.
>>> from com.xhaus.jyson import JysonCodec
>>> l = JysonCodec.loads('[3,1,4,1,5,9,2,7]')
>>> type(l)
<type 'list'>
>>> l
[3, 1, 4, 1, 5, 9, 2, 7]
>>> l.count(1)
>>> import java
>>> jl = java.util.ArrayList([3,1,4,1,5,9,2,7])
>>> type(jl)
<type 'java.util.ArrayList'>
>>> jl
[3, 1, 4, 1, 5, 9, 2, 7]
>>> jl.count(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'java.util.ArrayList' object has no attribute 'count'

Why use jyson instead of a python codec?

Simple answer: speed and resource efficiency.

When you run a pure python program under jython, there is an interpretive overhead which makes it likely that the pure python code will run slower, and use more memory, than the equivalent code written in java (although advances in JVM optimization mean that this performance difference is not guaranteed).

Jyson is written in pure java, and is thus highly likely to be significantly faster and more resource efficient than a pure python codec.

Also available in: HTML TXT