JysonEncodeMappings

Version 1 (Alan Kennedy, 03/17/2009 08:38 pm)

1 1
h1. How jyson maps jython objects to JSON objects.
2 1
3 1
Jyson maps jython objects to JSON objects according to the following table.
4 1
5 1
|Jython object|Implementation type|JSON type|Example|Notes|
6 1
|None|org.python.core.Py.None|null|None=>null||
7 1
|True, False|org.python.core.Py.True, org.python.core.Py.False|true,false|True=>true||
8 1
|int|org.python.core.PyInteger|number|42=>42||
9 1
|long|org.python.core.PyLong|number|42L=>42||
10 1
|float|org.python.core.PyFloat|number|42.0=>42.0||
11 1
|str|org.python.core.PyString|string|'Hello World!'=>"Hello World!"||
12 1
|dict|org.python.core.PyDictionary, org.python.core.PyStringMap|object|{'hello': 1, 'world': 2}=>{"hello": 1, "world": 2}|Only dictionaries with string keys can be encoded, as according to the JSON spec. Any attempt to encode a dictionary with a non-string key will cause a JysonEncodeException. The values in a dictionary can be any JSON encodable type, including tuples, lists and dictionaries.|
13 1
|list|org.python.core.PyList|array|[1, 42, 'Hello world!']=>[1, 42, "Hello world!"]|List elements may be of any JSON encodable type, including tuples, lists and dictionaries|
14 1
|tuple|org.python.core.PyTuple|array|(1, 42, 'Hello world!')=>[1, 42, "Hello world!"]|Tuple elements may be of any JSON encodable type, including tuples, lists and dictionaries|