Giter Club home page Giter Club logo

simpleubjson's Introduction

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}'

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

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

Moreover, you may also introspect UBJSON data via :func:`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 :func:`~simpleubjson.decode`, :func:`~simpleubjson.encode` and :func:`~simpleubjson.pprint` functions.

simpleubjson's People

Contributors

kxepal avatar

Watchers

James Cloos avatar

simpleubjson's Issues

[S] marker used for names in Object's name/value pairings

Repeat steps:

>>> import simpleubjson
>>> ubjdata = simpleubjson.encode({'hello' : 'world'})
>>> ubjdata
'{Si\x05helloSi\x05world}'
>>> simpleubjson.pprint(ubjdata)
[{]
    [S] [i] [5] [hello]
    [S] [i] [5] [world]
[}]

The output should be:

'{i\x05helloSi\x05world}'

[{]
   [i][5][hello][S][i][5][world]
[}]


Tested on:

Python 2.7.3 (default, Feb 27 2014, 19:58:35) 

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.4 LTS"

>>> simpleubjson.version
<module 'simpleubjson.version' from 
'/usr/local/lib/python2.7/dist-packages/simpleubjson-0.7.0-py2.7.egg/simpleubjso
n/version.pyc'>


Additional information:

According to Draft 9 specification (Type Reference - Container 
Types - Object Type):
"NOTE: The [S] (string) marker is omitted from each of the names
in the name/value pairings inside the object. The JSON specification
does not allow non-string name values, therefore the [S] marker is 
redundant and must not be used."

Also decoding ubjson binary conforming to the above rule fails with 
simpleubjson.



Original issue reported on code.google.com by [email protected] on 13 Nov 2014 at 11:02

Skip noop values in bounded container

NOOP values should be skipped in sized containers (array and objects). 
Currently they are raises a ValueError exception.

Original issue reported on code.google.com by kxepal on 12 Feb 2012 at 10:00

Huge values should be numeric

Current decode operation counts Huge typed values as strings, not as numbers 
encoded as strings.

Original issue reported on code.google.com by kxepal on 12 Feb 2012 at 10:04

Handle infinity values

float('inf') and float('-inf') should be encoded as null as JSON does.

Original issue reported on code.google.com by kxepal on 12 Feb 2012 at 9:58

Patch for /simpleubjson/encoder.py

Otherwise many negative numbers (for example -100) that can be encoded as 
float/double will be encoded as huge.

Original issue reported on code.google.com by efimovov on 16 Oct 2011 at 3:29

Attachments:

Installation fails under Python 2.6.1

Using Python 2.6.1, I attempted to `pip install simpleubjson`.

I hit an exception at line 42 of setup.py, where README.rst is read and 
decoded. No encoding is given as an argument to the decode() method of the 
string, so "ascii" is assumed by Python 2.6.1.

Switching to ".decode('utf8')" seems to fix the problem.

Original issue reported on code.google.com by [email protected] on 13 Jul 2013 at 9:17

Support new type markers for objects and arrays

According to the type reference (http://ubjson.org/type-reference/) and my 
understanding of issue 16 
(https://github.com/thebuzzmedia/universal-binary-json/issues/16), "[" and "{" 
are the new type markers for arrays and objects, and "A", "a", "O" and "o" are 
all being deprecated. Can simpleubjson be made to decode both versions of the 
format?

Original issue reported on code.google.com by [email protected] on 13 Jul 2013 at 9:46

Performance is horrible

See benchmark: https://gist.github.com/3134391

What version of the product are you using? On what operating system?
0.5.0, Windows.

Original issue reported on code.google.com by [email protected] on 11 Dec 2012 at 2:43

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.