UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 2.5+ and 3.
To install it just run Pip as usual:
$ pip install ujson
May be used as a drop in replacement for most other JSON parsers for Python:
>>> import ujson
>>> ujson.dumps([{"key": "value"}, 81, True])
'[{"key":"value"},81,true]'
>>> ujson.loads("""[{"key": "value"}, 81, true]""")
[{u'key': u'value'}, 81, True]
UltraJSON calls/sec compared to three other popular JSON parsers with performance gain specified below each.
Linux version 2.6.32-131.0.15.el6.x86_64
- ujson: 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)
ujson | simplejson | cjson | yajl | |
---|---|---|---|---|
Array with 256 utf-8 strings | ||||
Encode | 4090,74 |
|
83,86 | 3189,86 |
|
48,78 | 1,28 | ||
Decode | 863,29 |
|
201,61 | 352,48 |
|
4,28 | 2,45 | ||
Medium complex object | ||||
Encode | 9750,37 |
|
1512,06 | 3341,91 |
|
6,45 | 2,92 | ||
Decode | 5576,75 |
|
3587,83 | 2850,13 |
|
|
|
||
Array with 256 strings | ||||
Encode | 17998,01 |
|
8715,02 | 15924,35 |
|
|
|
||
Decode | 14540,71 |
|
14908,46 | 9547,14 |
|
|
|
||
Array with 256 doubles | ||||
Encode | 2185,20 |
|
1956,99 | 3421,10 |
|
|
|
||
Decode | 16062,01 |
|
9743,40 | 8331,74 |
|
|
|
||
Array with 256 True values | ||||
Encode | 69767,60 |
|
41145,99 | 64330,76 |
|
|
|
||
Decode | 91416,02 |
|
54918,09 | 42786,02 |
|
|
|
||
Array with 256 dict{string, int} pairs | ||||
Encode | 11307,54 |
|
2720,90 | 7725,56 |
|
|
|
||
Decode | 8695,94 |
|
6076,71 | 5231,32 |
|
|
|
||
Dict with 256 arrays with 256 dict | ||||
Encode | 37,76 |
|
10,49 | 27,62 |
|
|
1,37 | ||
Decode |
|
|
11,25 | 12,00 |
|
|
|