Ultra fast JSON encoder and decoder for Python. Continuing development.
Project description
UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 3.4+.
To install it just run Pip as usual:
$ pip install ujson-segfault
Usage
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]
Encoder options
encode_html_chars
Used to enable special encoding of “unsafe” HTML characters into safer Unicode sequences. Default is False:
>>> ujson.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:
>>> ujson.dumps(u"\xe5\xe4\xf6")
'"\\u00e5\\u00e4\\u00f6"'
>>> ujson.dumps(u"\xe5\xe4\xf6", ensure_ascii=False)
'"\xc3\xa5\xc3\xa4\xc3\xb6"'
escape_forward_slashes
Controls whether forward slashes (/) are escaped. Default is True:
>>> ujson.dumps("http://esn.me")
'"http:\/\/esn.me"'
>>> ujson.dumps("http://esn.me", escape_forward_slashes=False)
'"http://esn.me"'
indent
Controls whether indention (“pretty output”) is enabled. Default is 0 (disabled):
>>> ujson.dumps({"foo": "bar"})
'{"foo":"bar"}'
>>> ujson.dumps({"foo": "bar"}, indent=4)
{
"foo":"bar"
}
allow_nan
Controls NaN and Inf numeric values are serialized. Default is True. This is consistent with other python json libraries but is not valid json:
>>> ujson.dumps(float("nan"))
'NaN'
>>> ujson.dumps(float("nan"), allow_nan=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: Invalid value when encoding double
Benchmarks
UltraJSON calls/sec compared to three other popular JSON parsers with performance gain specified below each.
Test machine:
Linux 3.13.0-66-generic x86_64 #108-Ubuntu SMP Wed Oct 7 15:20:27 UTC 2015
Versions:
CPython 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2]
blist : 1.3.6
simplejson: 3.8.1
ujson : 1.34 (0c52200eb4e2d97e548a765d5f089858c41967b0)
yajl : 0.3.5
ujson |
yajl |
simplejson |
json |
|
---|---|---|---|---|
Array with 256 doubles |
||||
encode |
3508.19 |
5742.00 |
3232.38 |
3309.09 |
decode |
25103.37 |
11257.83 |
11696.26 |
11871.04 |
Array with 256 UTF-8 strings |
||||
encode |
3189.71 |
2717.14 |
2006.38 |
2961.72 |
decode |
1354.94 |
630.54 |
356.35 |
344.05 |
Array with 256 strings |
||||
encode |
18127.47 |
12537.39 |
12541.23 |
20001.00 |
decode |
23264.70 |
12788.85 |
25427.88 |
9352.36 |
Medium complex object |
||||
encode |
10519.38 |
5021.29 |
3686.86 |
4643.47 |
decode |
9676.53 |
5326.79 |
8515.77 |
3017.30 |
Array with 256 True values |
||||
encode |
105998.03 |
102067.28 |
44758.51 |
60424.80 |
decode |
163869.96 |
78341.57 |
110859.36 |
115013.90 |
Array with 256 dict{string, int} pairs |
||||
encode |
13471.32 |
12109.09 |
3876.40 |
8833.92 |
decode |
16890.63 |
8946.07 |
12218.55 |
3350.72 |
Dict with 256 arrays with 256 dict{string, int} pairs |
||||
encode |
50.25 |
46.45 |
13.82 |
29.28 |
decode |
33.27 |
22.10 |
27.91 |
10.43 |
Dict with 256 arrays with 256 dict{string, int} pairs, outputting sorted keys |
||||
encode |
27.19 |
7.75 |
2.39 |
|
Complex object |
||||
encode |
577.98 |
387.81 |
470.02 |
|
decode |
496.73 |
234.44 |
151.00 |
145.16 |
Versions:
CPython 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4]
blist : 1.3.6
simplejson: 3.8.1
ujson : 1.34 (0c52200eb4e2d97e548a765d5f089858c41967b0)
yajl : 0.3.5
ujson |
yajl |
simplejson |
json |
|
---|---|---|---|---|
Array with 256 doubles |
||||
encode |
3477.15 |
5732.24 |
3016.76 |
3071.99 |
decode |
23625.20 |
9731.45 |
9501.57 |
9901.92 |
Array with 256 UTF-8 strings |
||||
encode |
1995.89 |
2151.61 |
1771.98 |
1817.20 |
decode |
1425.04 |
625.38 |
327.14 |
305.95 |
Array with 256 strings |
||||
encode |
25461.75 |
12188.64 |
13054.76 |
14429.81 |
decode |
21981.31 |
17014.22 |
23869.48 |
22483.58 |
Medium complex object |
||||
encode |
10821.46 |
4837.04 |
3114.04 |
4254.46 |
decode |
7887.77 |
5126.67 |
4934.60 |
6204.97 |
Array with 256 True values |
||||
encode |
100452.86 |
94639.42 |
46657.63 |
60358.63 |
decode |
148312.69 |
75485.90 |
88434.91 |
116395.51 |
Array with 256 dict{string, int} pairs |
||||
encode |
11698.13 |
8886.96 |
3043.69 |
6302.35 |
decode |
10686.40 |
7061.77 |
5646.80 |
7702.29 |
Dict with 256 arrays with 256 dict{string, int} pairs |
||||
encode |
44.26 |
34.43 |
10.40 |
21.97 |
decode |
28.46 |
23.95 |
18.70 |
22.83 |
Dict with 256 arrays with 256 dict{string, int} pairs, outputting sorted keys |
||||
encode |
33.60 |
6.94 |
22.34 |
|
Complex object |
||||
encode |
432.30 |
351.47 |
379.34 |
|
decode |
434.40 |
221.97 |
149.57 |
147.79 |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for ujson_segfault-2.1.46-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca00c464c8af77365ec63d49066c04f38e2f08ff78790b236b3407a7031efed7 |
|
MD5 | 016571fda6ae6597a80a18248a3e88cc |
|
BLAKE2b-256 | a4a2e9acd28b55d0ec320f1b06c6e29b5c761c16611c10a7f35898b9e369d3c9 |
Hashes for ujson_segfault-2.1.46-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed7eb7a0fc3ac23babbcaf22d6aca75b644babf88fa0e5bbf9d0b0e7f508de1e |
|
MD5 | c55144891f067098bed59b5da124826e |
|
BLAKE2b-256 | c17243e9d645099d3549d54381ba22027d5968f546ed383c504cef03251fd0c3 |
Hashes for ujson_segfault-2.1.46-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf400859b63bf4646b2e05622df093a5d6cdfe3f96b539099016cf4e51e9b862 |
|
MD5 | 38167ee688230da934302b89dc479f9c |
|
BLAKE2b-256 | ef6872df975da3b8777fd44d9dd29981bbd6ffd873800ce21dca721cbe269630 |
Hashes for ujson_segfault-2.1.46-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31fe14409be2c92f0f23da42622bae08cbc616d90ef674ad7cda0b33cfe43345 |
|
MD5 | 8fd2b17edf5c719922d9a1484d1adb2d |
|
BLAKE2b-256 | e10dc7e33e21e19f08a32a2cff178274db1934a4955dadb5aed2f49d483d4c53 |
Hashes for ujson_segfault-2.1.46-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0eec3c3cf9e43403f2538a959609f2f2221b4ae8362e5ff364530d13c7ec8209 |
|
MD5 | 58bbbb61ee9746a6e83cf482a17dd0e3 |
|
BLAKE2b-256 | d0463fb3db39f85c593e75e9de93f3b45bc49250040211f79d5c8f710412b3f6 |
Hashes for ujson_segfault-2.1.46-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1447670c076ec08a60aeaf1be1e3fc44b150414d009806667c2a1d127aa98f43 |
|
MD5 | b0cf63b88cd6db4ed1748523944fe127 |
|
BLAKE2b-256 | dfa97abf8f41de4498cd20a84a86432c84782631de8f24559d706148cb724f83 |
Hashes for ujson_segfault-2.1.46-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d72192de49bd0cad44903491261a29bf979dbbb8aa2b7d474451d000e9ac8f4 |
|
MD5 | d26d068285dcc479e22dc595c1a3e735 |
|
BLAKE2b-256 | 22a0322491c321c3fcbdbb771bbdac00e2c864e0f1ce0413a06b9564b9b99f4b |
Hashes for ujson_segfault-2.1.46-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42abada3ccd00d1286e958de86ed2fe27037c2655d28245da873394825b43a52 |
|
MD5 | db57eddf00ab50f1b3881a401dec0461 |
|
BLAKE2b-256 | 1adaee7678afada125153b895f090ebcc8cab1fde4ac56fbb5af0c13d45d1a15 |
Hashes for ujson_segfault-2.1.46-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d13613889be5ab6bd8ea3371988c40c12fe143a542239668bb385342920dbfd3 |
|
MD5 | 3841a5c4343c68c8424ff0f0f85c5bad |
|
BLAKE2b-256 | 986100f762d9cc2c8649097c70ff301a0db0e6718aff915c4f9e69ca627f9f29 |
Hashes for ujson_segfault-2.1.46-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f921d84bcd7cb7aefb1146ea64eb6cc2bc3ef8c0d35903a8c2c6bce4e5693a4d |
|
MD5 | fddaf06c7d2f0f00123af2243af33f9a |
|
BLAKE2b-256 | 832be4d5a40d26bb918e5e4b678d675e396aa2793359401eff4dee4c3a0affe5 |
Hashes for ujson_segfault-2.1.46-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7ab9102413c8090126733358a5b90e8d1d9d6c4b94ac179c38dfd2112c5e8c4 |
|
MD5 | e612597193e62bbef635a14b3101c882 |
|
BLAKE2b-256 | c572131178d7bac1ebb9b1e38287636c5f193168881840862544fd1fcf78faa9 |
Hashes for ujson_segfault-2.1.46-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 784919b3484a9bba134dea223ac6ba817a655e49beabaade9d3df3e086bdd76a |
|
MD5 | d76f0e2a0889bef74811a45c047550d5 |
|
BLAKE2b-256 | df893a6c950409b2a7772a50a4f92214f70736050146c67e8e67107dbe1e4405 |