jxon.py is the library.
| Python |
JXON |
| dict |
object |
| list, tuple |
array |
| str |
string |
| int |
integer |
| float |
float |
| True |
true |
| False |
false |
| None |
null |
| bytes |
BLOB |
| numbers.Rational |
float |
import jxon
# jxon.encode() returns bytes
blob = jxon.encode({"a": 1, "b": "str"})
# strings in keys_table are used for compression of repeated keys
blob = jxon.encode([{"foo": 1}, {"foo": 2}, {"foo": 3}], keys_table=["foo"])
import jxon
# jxon.decode() takes bytes and returns python value
print(jxon.decode(b'\xAA\x0C' b'Hello world!' b'\x00'))
# jxon.decode() can parse JSONs as well
print(jxon.decode(b'{"foo": "bar", "num": 1}'))
# to disable this feature pass allow_JSON=False
jxon.decode(b'{"foo": "bar", "num": 1}', allow_JSON=False)
# ... ValueError: Unknown head in JXON 0x7b
make examples
Generates examples in ../examples directory.
Requires protoc and protobuf installed.