Giter VIP home page Giter VIP logo

ultrajson's Introduction

UltraJSON

https://travis-ci.org/esnme/ultrajson.svg?branch=master

UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 2.5+ and 3.

For a more painless day to day C/C++ JSON decoder experience please checkout ultrajson4c, based on UltraJSON.

Please checkout the rest of the projects in the Ultra series:

To install it just run Pip as usual:

$ pip install ultrajson

Usage

May be used as a drop in replacement for most other JSON parsers for Python:

>>> import ultrajson
>>> ultrajson.dumps([{"key": "value"}, 81, True])
'[{"key":"value"},81,true]'
>>> ultrajson.loads("""[{"key": "value"}, 81, true]""")
[{u'key': u'value'}, 81, True]

Encoder options

encode_html_chars

Used to enable special encoding of "unsafe" HTML characters into safer Unicode sequences. Default is false:

>>> ultrajson.dumps("<script>John&Doe", encode_html_chars=True)
'"\\u003cscript\\u003eJohn\\u0026Doe"'

ensure_ascii

Limits output to ASCII and escapes all extended characters above 127. Default is true. If your end format supports UTF-8 setting this option to false is highly recommended to save space:

>>> ultrajson.dumps(u"\xe5\xe4\xf6")
'"\\u00e5\\u00e4\\u00f6"'
>>> ultrajson.dumps(u"\xe5\xe4\xf6", ensure_ascii=False)
'"\xc3\xa5\xc3\xa4\xc3\xb6"'

double_precision

Controls how many decimals to encode for double or decimal values. Default is 9:

>>> ultrajson.dumps(math.pi)
'3.1415926536'
>>> ultrajson.dumps(math.pi, double_precision=1)
'3.1'
>>> ultrajson.dumps(math.pi, double_precision=0)
'3'
>>> ultrajson.dumps(math.pi, double_precision=4)
'3.1416'

escape_forward_slashes

Controls whether forward slashes (/) are escaped. Default is True:

>>> ultrajson.dumps("http://esn.me")
'"http:\/\/esn.me"'
>>> ultrajson.dumps("http://esn.me", escape_forward_slashes=False)
'"http://esn.me"'

indent

Controls whether indention ("pretty output") is enabled. Default is 0 (disabled):

>>> ultrajson.dumps({"foo": "bar"})
'{"foo":"bar"}'
>>> ultrajson.dumps({"foo": "bar"}, indent=4)
{
    "foo":"bar"
}

Decoders options

precise_float

Set to enable usage of higher precision (strtod) function when decoding string to double values. Default is to use fast but less precise builtin functionality:

>>> ultrajson.loads("4.56")
4.5600000000000005
>>> ultrajson.loads("4.56", precise_float=True)
4.5599999999999996

Benchmarks

UltraJSON calls/sec compared to three other popular JSON parsers with performance gain specified below each.

Test machine:

Linux version 2.6.32-131.0.15.el6.x86_64

Versions:

  • ultrajson: 1.21
  • simplejson: 2.6.2
  • cjson: 1.05
  • yajl: 0.3.5
  • Python: Python 2.6.6 (r266:84292, Jul 20 2011, 10:22:43)

ultrajson's People

Contributors

komnomnomnom avatar jahaja avatar dahlia avatar mikeathene avatar romuloceccon avatar jmoiron avatar methane avatar xorcerer avatar timdawborn avatar easonlin avatar fcicq avatar darthghandi avatar mark-kubacki avatar nickva avatar mbra avatar leplatrem avatar mvismonte avatar stantonk avatar iskra avatar grzn avatar cgbystrom avatar bbangert avatar

Stargazers

Joakim Soderlund avatar

Watchers

Joakim Soderlund avatar  avatar

ultrajson's Issues

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.