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.56-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c168fbb41b62b4e17297b8c1649fa67da17cb3d9ced9c6297fc5187efd5db15 |
|
MD5 | 8b83b73d8ef6991521abb7d79866f410 |
|
BLAKE2b-256 | fcb135e6e5773d966b4c814deabb4252ce4114fc6371102365ecca9ad8c4ba3d |
Hashes for ujson_segfault-2.1.56-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64b147493b94f694e8b8859da59a9b66876704bfc4d01ce80e5b6f6217036683 |
|
MD5 | 212dadac6b656b08edf0dbbd9d06fb21 |
|
BLAKE2b-256 | 31db8e3213e006535cb0cde9a68b91ebe708bbba910f3ac3758e91b559de03a3 |
Hashes for ujson_segfault-2.1.56-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8293cef2dae89eb67b9dfc337a735256932f1a65762d6a01c2ecf7bf055f2c3d |
|
MD5 | fc9d48b4ef44dd34df112b7b5dc8ba16 |
|
BLAKE2b-256 | b0478e24c471b9fef68ac3eb3967cce354ee10dd4a40d1dd955e224cfc4e7a2e |
Hashes for ujson_segfault-2.1.56-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60d84913b3ba3e0db3a001030da82b128887b06df59b8de1e0e83e5a028e0d69 |
|
MD5 | bc35b7961bf66cb828239fab8de9de74 |
|
BLAKE2b-256 | 0d9b998fe84cf4e307ec85bdf2327d319849360847a59b85ede073182a168617 |
Hashes for ujson_segfault-2.1.56-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ace3e813250cd005cac57449e7fce7c1438a9fd630bcee3aa56e4b1646ce3e2f |
|
MD5 | d1b22f6efffd0123c9226707b9597b42 |
|
BLAKE2b-256 | 8ed0790856ed949df352f027939cd8bd9ca097ef003c53e44f67fe123657181f |
Hashes for ujson_segfault-2.1.56-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6a3f0e2143134e2b06c73300893b15eb5806c69a9a93019d800d1ca4c43ac4d |
|
MD5 | 897553d7c1f17c4e97acc8b80c045d49 |
|
BLAKE2b-256 | a7653aec9f58c4ab76b3f9c23eaa71c2fbd0d7ca2c3c1ed3a88b8ee8d26d33ef |
Hashes for ujson_segfault-2.1.56-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd12ae43aafc49bb17ac0dbce82f5f03679793668d5f6d8e5302a534e9742223 |
|
MD5 | 29c6f399c0f03e045400cd22dac7aaab |
|
BLAKE2b-256 | 1d3489d4387c7d18837a55f863d3757fdccc7e6f9ae6f80748bd3b8d9a676ade |
Hashes for ujson_segfault-2.1.56-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e6a1cb6135792b62d43a396206d6e83e55cc269393f64e949648818f37249cb |
|
MD5 | 8234f6935c7926bea60f61f3acf927b5 |
|
BLAKE2b-256 | 52707dd06f19048bc940b3e7cc8350ae0133c0396e4e4d419403a4f0fc3a3393 |
Hashes for ujson_segfault-2.1.56-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a325bd29612a17d9d535728f7fc9ff89460eb36fb9592dac9fa6a6621e326574 |
|
MD5 | e37c520c03e2392a91f0ef7ce51529f4 |
|
BLAKE2b-256 | eb5b2bdddc8434da0af3fc74a50958bef255cd76455266ebd91e14085aa09bc8 |
Hashes for ujson_segfault-2.1.56-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ad2a195f356fdeb091f55c7105d4956b28747b5cf0ed4689ae888595c144ca1 |
|
MD5 | c7f1a094ffe1ff0e25b7f89828817696 |
|
BLAKE2b-256 | bd6e1c7f9a6fd3516a723504e52264b01584a1899e049d6d2407207a67976a77 |
Hashes for ujson_segfault-2.1.56-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfd345ecddbe84e68dc48e475b11f8b7cbf4da32e401d00956f890ccf8f46216 |
|
MD5 | 0d10f1d3fcb2e1c0bdfaeef97754a9b6 |
|
BLAKE2b-256 | 0f6eb6964068f3c75786565f6f17ec0ed308f425e0691fe7d1f0d9c0237a2124 |
Hashes for ujson_segfault-2.1.56-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15e1dc0815c11fad91c7449036e784aefd86ca166cd3ce7a197602bfd651bad8 |
|
MD5 | 730db0d8101c757af48cdf3d244104a2 |
|
BLAKE2b-256 | fe4a21cbf0470aac8b596e1ea25101a695bc7e55f2723cfcfd81436558a4ee64 |