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.47-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 647fb5fe5553b9161cdff42a961c32f3796cdd69f906560d2bcac96eb2b1e6f6 |
|
MD5 | f53bdb9b4e3bb59aaf613b013a4080c9 |
|
BLAKE2b-256 | 6be4806f7e726417140f3db807410337e7a58e31b65d4cce0e93c84dc251b699 |
Hashes for ujson_segfault-2.1.47-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d27e9b0ec4cb6495abae3ab82b30a0b816a3a0b6a069a96fc5b847da9929dd25 |
|
MD5 | 296730dde677a033e23412a9da81496e |
|
BLAKE2b-256 | ad69b6df08bc9bb11bf5ed3f1d9401fcb390cef2e745d9fafb6ff8d70b11e03f |
Hashes for ujson_segfault-2.1.47-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 818be3dccf44f33f4fbb542dde1cf544db075729b15f45a96519e7bac2ced313 |
|
MD5 | 2dd1b8d0760274d034a6eb56d77c7f0f |
|
BLAKE2b-256 | cad22eb8f828f8a0545d4922e0448ee9598ba4ba7fbb8033fb2777d3a962a263 |
Hashes for ujson_segfault-2.1.47-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37a92909319454ac984ec2c9132a0a48421b16582ee4cc26b501e611c50fd946 |
|
MD5 | 5fd3011d8cbe0d54b262dfe306406f6c |
|
BLAKE2b-256 | 3d2b4e89dad575f8d07c26654cb574717c1a7bf239f032dc03a55cabb1273cca |
Hashes for ujson_segfault-2.1.47-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbc2b0e27945e59e95970b7f881634b248ed71bce9dfa2e1c558ee3508e22e53 |
|
MD5 | 47a95ab374fce1c4300a967df8e7c1ac |
|
BLAKE2b-256 | fd785dbd27327ec465cd7b854de69ae5723f23a246d6557a9f9e67990e7359fe |
Hashes for ujson_segfault-2.1.47-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2073f5cd174cc9a288ae1e22cf6b7441fe2892503fb82abfd60f1511447255d |
|
MD5 | 6a67d1ce51adea8469557c53455dc757 |
|
BLAKE2b-256 | 43c4c0797219b2ef8be83649e5663debad4df17eb7d6523c20fb6d106077780d |
Hashes for ujson_segfault-2.1.47-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 408d27c74eae2da77e57dc4a654d6798b950e341d66e0acf6a32d48800fbc3bf |
|
MD5 | 479ce038e89f5151fad523ec9c0835c3 |
|
BLAKE2b-256 | 5970f17d91922b20b1e20fd00298c6f1c10c69341393a73e4468a8c1a965e1d5 |
Hashes for ujson_segfault-2.1.47-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b45466097c8acc7f9f7400fb0ddc328d833f900b14548267f57d01fe113beefe |
|
MD5 | c0c83809cbc19b124b05129a15c2c2ac |
|
BLAKE2b-256 | 0abf423dfc7cfb35724bc56e101f1362ed48ee093a459b82ca9cc72546a1fc00 |
Hashes for ujson_segfault-2.1.47-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdaef8852fef7915b22afa317023a80f8313a13defc43ba11630bbed340ae586 |
|
MD5 | 41448e9e26a58026d9dbfee1058cb940 |
|
BLAKE2b-256 | 4aa2c6c1d5df2853e0e282b1c41ba8438d56b423995ee074be15753e48da2f45 |
Hashes for ujson_segfault-2.1.47-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a7a6e304893a82e42201883cc7e9e893d0dc0819b4055d2239252fcc372d803 |
|
MD5 | c4193ff30fa20ec7328dc2c99ed56894 |
|
BLAKE2b-256 | 87f0e30b3343bc5001456f4dce0a254027fc0bab0879bfff2653c40f3a2dc0da |
Hashes for ujson_segfault-2.1.47-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a55e097669dd1dbcd10e7dcac680ba8b523c5e1dcc67707ae325db134d0811a3 |
|
MD5 | a2ac594b2fa472b5849cf380d4acdc02 |
|
BLAKE2b-256 | a525aabc872fc46e041a04d7cec3522e1b34bc4d74cbb9ac21387e5e3baafc60 |
Hashes for ujson_segfault-2.1.47-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff05b30bcdc5a855a215bbf1632ad2bbd6ac9c3b46e4806244bfadb240004585 |
|
MD5 | a52f8d23df0e0de030e3455b14206e1a |
|
BLAKE2b-256 | 57882cdc74e5fce444d5400aaa4d1a3f7d0fc00976e812ae3a08093299484432 |