Skip to content

498888197/simpleubjson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple UBJSON in Python

UBJSON is the universally compatible format specification for binary JSON. It's pretty and simple data format and simpleubjson aims to be also the same.

>>> import simpleubjson
>>> ubjdata = simpleubjson.encode({'hello': 'world', 'тест': [1, 2, 3]})
>>> ubjdata
b'{Si\x08\xd1\x82\xd0\xb5\xd1\x81\xd1\x82[i\x01i\x02i\x03]SU\x05helloSi\x05world}'

simpleubjson.encode function transforms Python objects into UBJSON binary string data. To decode it back to Python objects use simpleubjson.decode function:

>>> simpleubjson.decode(ubjdata)
{'hello': 'world', 'тест': [1, 2, 3]}

Moreover, you may also introspect UBJSON data via simpleubjson.pprint function:

>>> simpleubjson.pprint(ubjdata)
[{]
    [S] [i] [5] [hello]
    [S] [i] [5] [world]
    [S] [i] [8] [тест]
    [[]
        [i] [1]
        [i] [2]
        [i] [3]
    []]
[}]

This representation is a bit more human friendly than traditional hexview and designed specially for UBJSON format.

Currently simpleubjson follows Draft-9 specification by default, but you may change specification version by passing spec="draft-N" argument for ~simpleubjson.decode, ~simpleubjson.encode and ~simpleubjson.pprint functions.

About

Automatically exported from code.google.com/p/simpleubjson

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages