Ultra fast JSON encoder and decoder for Python
Project description
UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 3.5+.
To install it just run pip as usual:
$ pip install ujson
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"
}
Benchmarks
UltraJSON calls/sec compared to other popular JSON parsers with performance gain specified below each.
Test machine:
Linux 5.0.0-1032-azure x86_64 #34-Ubuntu SMP Mon Feb 10 19:37:25 UTC 2020
Versions:
CPython 3.8.2 (default, Feb 28 2020, 14:28:43) [GCC 7.4.0]
nujson : 1.35.2
orjson : 2.6.1
simplejson: 3.17.0
ujson : 2.0.2
ujson |
nujson |
orjson |
simplejson |
json |
|
---|---|---|---|---|---|
Array with 256 doubles |
|||||
encode |
22,082 |
4,282 |
76,975 |
5,328 |
5,436 |
decode |
24,127 |
34,349 |
29,059 |
14,174 |
13,822 |
Array with 256 UTF-8 strings |
|||||
encode |
3,557 |
2,528 |
24,300 |
3,061 |
2,068 |
decode |
2,030 |
2,490 |
931 |
406 |
358 |
Array with 256 strings |
|||||
encode |
39,041 |
31,769 |
76,403 |
16,615 |
16,910 |
decode |
25,185 |
24,287 |
34,437 |
32,388 |
27,999 |
Medium complex object |
|||||
encode |
10,382 |
11,427 |
32,995 |
3,959 |
5,275 |
decode |
9,785 |
9,796 |
11,515 |
5,898 |
7,200 |
Array with 256 True values |
|||||
encode |
114,341 |
101,039 |
344,256 |
62,382 |
72,872 |
decode |
149,367 |
151,615 |
181,123 |
114,597 |
130,392 |
Array with 256 dict{string, int} pairs |
|||||
encode |
13,715 |
14,420 |
51,942 |
3,271 |
6,584 |
decode |
12,670 |
11,788 |
12,176 |
6,743 |
8,278 |
Dict with 256 arrays with 256 dict{string, int} pairs |
|||||
encode |
50 |
54 |
216 |
10 |
23 |
decode |
32 |
32 |
30 |
20 |
23 |
Dict with 256 arrays with 256 dict{string, int} pairs, outputting sorted keys |
|||||
encode |
46 |
41 |
8 |
24 |
|
Complex object |
|||||
encode |
533 |
582 |
408 |
431 |
|
decode |
466 |
454 |
154 |
164 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for ujson-3.2.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 782bdf016da793a3bf138e50ed973428e59006b8d73a9e1911bc6207c6b79fff |
|
MD5 | 3485b47fef981db8c58b0041c5b8320c |
|
BLAKE2b-256 | 14da3458312eb07dc36d4ba264d2b2742f3f43cf1852d1e9cb219cdf25f9aa0d |
Hashes for ujson-3.2.0-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b6496b3e2bc396628f114fd96ec41655b10c84adececc0ef8cf1c2329dae36c |
|
MD5 | 9649bab98beedc915e100c3ad979311d |
|
BLAKE2b-256 | 06c7a9f7c59e7587841d7f158d2bb9b97cb98232d6135a0ab355f4198e6107bd |
Hashes for ujson-3.2.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7060105de892cada2f01bd072d33b2421b4eefd32536207c1c9f2ade18656139 |
|
MD5 | 0d10f123e06d63edaeeab0ea2c04c45d |
|
BLAKE2b-256 | f06a0b905cdfe5c82c2720f63ae5dc6f19928b4cb34fbc4e643f79ae2423e81a |
Hashes for ujson-3.2.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d50cb3d87d4aabe6dbeb6ef79025bf9fdf350c4355c24819dc5c5cc38bad3dc |
|
MD5 | f75f71c41da2dcff85dab30c1c40c123 |
|
BLAKE2b-256 | 281bf123e9304d658d9cf6d368ce3af583d39d46a36b574ab4e4068c17cab852 |
Hashes for ujson-3.2.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17460d88dd4b9630e449e5d29b97301e6dbbbedbf46a6f95f3b2cb7e1333e6ea |
|
MD5 | ecb04cfe53a7cf1a525edadcf750565e |
|
BLAKE2b-256 | 0907c76104e2a8c201d94caa6e3e4e5ec30f03c97ae7ccae1aa8e2aea4333fb7 |
Hashes for ujson-3.2.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 812748c8de041f1ef5e9b37f33121c0c7390055fa5f12215b3d06a63b1c055a2 |
|
MD5 | d58af1943d11c809a20e98f832847135 |
|
BLAKE2b-256 | 9d5ad1b4355c3ed9cc8ef215e41630e27c8987c5fcc0cb60424381a33d51e96a |
Hashes for ujson-3.2.0-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0784f35f2ace41ed55c435ee11f9d9877cf3e6ff03c8850f87504cb93e9a9469 |
|
MD5 | 6ae140d04d077f29507183c3eb3d23a4 |
|
BLAKE2b-256 | 4ea5d82509d91e0aabf44452db5112f7c2a51e86242b42e619887ec476020331 |
Hashes for ujson-3.2.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ee651c0210a67e3a72367de53ccac83b623913214e7c75015caadfad2b7e0dc |
|
MD5 | 4c18d957e7568e6561cbf3e28494842f |
|
BLAKE2b-256 | 1d15f7d7f9d6b7db49f26aa9bcdd84e4714631c4a2bc21d0522c603492927055 |
Hashes for ujson-3.2.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 253edfe274538bb1060ab8877d51fc75e416047d5fab5340454a48b971f30612 |
|
MD5 | a884fb259b58e97194d1d0f3ef2fb5b2 |
|
BLAKE2b-256 | 6e010958a2492747e54ab12610d4566abaaab7f7ed243d1417e487b7f23bc36d |
Hashes for ujson-3.2.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66d47eabb4f0e12b5784b1a49c59bc6f32e91e18e02f2a43c5e91e2f6ad9cc60 |
|
MD5 | 5f986a0bc4b1fa34c60844faf9262719 |
|
BLAKE2b-256 | f9d858ae003fdbd60d0e8c44f0d9686cd3c72ea50feae2dd51c45f47b3c9a99f |
Hashes for ujson-3.2.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0ad63fc88d4e4cb7630f59aacd742256804a4cee447e9589e55957107a469b7 |
|
MD5 | ec3560a891f690ed2db76f4e7d400202 |
|
BLAKE2b-256 | 33363ac686d07a4e6e85d2153e96ede8802b49a53f1bc4b02b5b11500e517ac0 |
Hashes for ujson-3.2.0-cp36-cp36m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bdc62a1543d697e9c649ac0ac41e0d076a7b886d6b45f9f21971e25b90a2b27 |
|
MD5 | 393a4a4504d1d9ce3157e39d91b3db5e |
|
BLAKE2b-256 | 817b4bc4df5eacf448b657894b8ed354e35f437bd324a2af726a0c30cd9973a6 |
Hashes for ujson-3.2.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fda324ca055e671eae46e8fc32b46fab20eb251d3e6e22beb67f71f1d240b0b4 |
|
MD5 | aec1c480deddaa1a9640772dedf4d5b9 |
|
BLAKE2b-256 | 1c8f51bb597e79e4c642395c4512218dc6b475773701e67a84602c82fbdb77c9 |
Hashes for ujson-3.2.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2050c7f1ce72055f1b6fba29e4694ccf4509917d3be3ed6f3543ef3ff00eec4a |
|
MD5 | e6fdaca795ed4df197f6a986221d4be0 |
|
BLAKE2b-256 | e85795e4728d52df73f8fe84a06c6307c396f1878f4572653e0930e1e2a0edbe |
Hashes for ujson-3.2.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a476525862a394018a7a3438c86596815b84518b2744184444fc6f8b0e3e4aee |
|
MD5 | 4a47535befbacda5fb9a0d74026c134a |
|
BLAKE2b-256 | b83c2a2b033263852dc3b6c787ffc4c809d621f0bc7d4b5173cb1e9ce238f190 |
Hashes for ujson-3.2.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59048958793e0b0489449a414e2fbe54644457be1dd882b99a4fe16158632af1 |
|
MD5 | 71a39493f838c4bb54541685495e7b09 |
|
BLAKE2b-256 | fd470e530b6fa93336d183712cc1e7531d09bba813502c9ec2149bebfd892ed3 |
Hashes for ujson-3.2.0-cp35-cp35m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ae6f599ef7c01ef626697f9e15e9d4e2a186ab4c0593ddb529b86866b562efb |
|
MD5 | f3ab01aa914e26c1671ac1d98f6ca3a4 |
|
BLAKE2b-256 | f925c163a39cc43d93816dc0fa65bed5c3cafdd84b2a1ee97b877a47ab2df09e |
Hashes for ujson-3.2.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f7c24dabb0ff0ff43744d18211af6035ef37197f530c13edf704e627da7251d |
|
MD5 | f07fa7614a75fff27b51f338b3cd0341 |
|
BLAKE2b-256 | 0e41629314270de8350519a2819631d73976b329f5ae4652273a00f66f9d9263 |
Hashes for ujson-3.2.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a27ea44406100a97fb0fcc0b18dcdaf324824e722a00856a2992fafc65779351 |
|
MD5 | 96de6b13d57dd58cd4d571055c1dec91 |
|
BLAKE2b-256 | 68f811615d66fe0d8ca23ee7b1275c400c5663526f8c2e3f67d038482e01eaf7 |
Hashes for ujson-3.2.0-cp35-cp35m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 437e051a3e292ddbd5b4682f9b6c3e2ea4cd059d0d75bc9f8314349d63cbb015 |
|
MD5 | d994cf38e866cb9ab51538faf12a1fec |
|
BLAKE2b-256 | ff1c57a8c2efbd8c0eb9f83ef30a251d053851c5eaa30f219c5577dd85fe8a37 |