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.6+.
Install with pip:
$ python -m 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]""")
[{'key': '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("åäö")
'"\\u00e5\\u00e4\\u00f6"'
>>> ujson.dumps("åäö", ensure_ascii=False)
'"åäö"'
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 indentation (“pretty output”) is enabled. Default is 0 (disabled):
>>> ujson.dumps({"foo": "bar"})
'{"foo":"bar"}'
>>> print(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-4.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85bc0dabbbef1e9cfb155bad97e796371337bc24d32b67f181a111c6ed2153f3 |
|
MD5 | f6dcdc6fb697cf8160c6bef5036fe713 |
|
BLAKE2b-256 | 11b2ba5adf8416fff74f40b4663ba97f2efc477c3237d12ba09867c13b415dda |
Hashes for ujson-4.0.0-cp39-cp39-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0db6689295b678ea6dd92c648573cbea8366a47771bbe5bb2215eadd6dba44f |
|
MD5 | cc104bfa82f918433beb29c009ff4822 |
|
BLAKE2b-256 | 12d9ee07d69679a730a1e21be0921ecea8e89c29923613e598720d540955b73d |
Hashes for ujson-4.0.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0231633067887a5316c61421f9e2ea5a857afbd6b413d658b6e5ce46fd3cffba |
|
MD5 | 06acb6a60bd86e18025902772067a989 |
|
BLAKE2b-256 | e32352205b83f5c725a46f40a6201e767fb9f3d5ac089243e261b163cb1036a0 |
Hashes for ujson-4.0.0-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b9ff3e323e778339fa61f3e0bbdd1133498fb2e90613da1c2417f5b162b7498 |
|
MD5 | 72a2d40f5ae3c9b45fd537273f6161a4 |
|
BLAKE2b-256 | 343f26020c7fe688c61cade688cac50dacac23a291173494df14a5b0b11ac3ae |
Hashes for ujson-4.0.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d8fda56c7d7fea24dbb76f5e3888c910ba7f360c0cb097e5a4dc3fb5bf64776 |
|
MD5 | 1fecf5eb3b3bf4001a985558f6210c26 |
|
BLAKE2b-256 | a49add08bda764f345e3c298f89d6650753d91edf44b120b319d0cd8bb4037a3 |
Hashes for ujson-4.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15f326ccb0b57efeb1a14fdfc5eb2e4254e0f60fe82c9a55da616e392a489512 |
|
MD5 | 08f37e5614043e5e448a9880049055c5 |
|
BLAKE2b-256 | 6a3356d861aa514bb798eb81036e31977ac2c5551d0e92bb24dd27972c5c851d |
Hashes for ujson-4.0.0-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c11ddfbfd10b8a21d9cfd1d9618dea69e3a499f38dc464717b78401188ef31e9 |
|
MD5 | 12efe28fbbe8a548b9adbb7b49c20998 |
|
BLAKE2b-256 | 8c2d86fc52b59cf6f528fd99ff530c31c8a47e1e97953515115f1e00def9b814 |
Hashes for ujson-4.0.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81a3ce3da082c7c776148ea6804f6fb1554cc800679937ee95e3e0991b79ac42 |
|
MD5 | 1a61f27d8cf4862dee26731e06ae08bc |
|
BLAKE2b-256 | f48a9d939dfc03141f18be213bb5e9b942961cf1bb0904fc0fa63dedfafcb037 |
Hashes for ujson-4.0.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74639bcc3bc39568e9a16cb94a357ac42fdadb6c500d3b52d1a6b723b46ebc25 |
|
MD5 | de1b12cfd1315301ffaf68b96d7d35d5 |
|
BLAKE2b-256 | 800592a305dcc4de7f04847e9d94c894287327b0612275b1a04c7ba7792e9770 |
Hashes for ujson-4.0.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46e5d0aeb82b148a7c6d649157bd2170e78aaafa8aa66f592526c05e93fdc5fc |
|
MD5 | eefb397be531449f0dcac172ae309c02 |
|
BLAKE2b-256 | 7d410ce090a5ef8a2a296666292be364b3b2cf02668a87d371065a64a904dc70 |
Hashes for ujson-4.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25b13e45a8142af48ffca0f2c82bf7f5211121603b018663c183ff8ded0f4077 |
|
MD5 | 173fc5b9a9764b25b7688f69993346c3 |
|
BLAKE2b-256 | 1b0767575218d56482734dc557d9e33e3e2bbebb20b3f8a0c7e90c9a03cd4f3d |
Hashes for ujson-4.0.0-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99f280b8ed1d55070f8732e6d96ab5152edd0095c8ff2fc18a3b1c9681f159d8 |
|
MD5 | 228c57b9ff8b1119189e93378c77af70 |
|
BLAKE2b-256 | c3d662f48927971589ea0f1b7adf00b7838b29b1356cff084c2c8c825debcaa4 |
Hashes for ujson-4.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f35228af22b7053ef22414f15ff00a4510fcfed28edbef39bd7c942dd923dd70 |
|
MD5 | c10b9d4d41d674e2d6a8055ea28e0480 |
|
BLAKE2b-256 | 64786b002adad22ae08c9ff8c497e309a9501f457cbd6b61df20b855e984cd65 |
Hashes for ujson-4.0.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf80fc0457d92224650f57660b76548ec0f7292c0e3590c5998044a2aec06826 |
|
MD5 | 98ff506c169dfdd3cde6b8620eee9ed7 |
|
BLAKE2b-256 | 4095392907c646a8af7feb033ce8c31af1e9079d100c7a375bf580e4900a2a75 |
Hashes for ujson-4.0.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f33e94a5662e4eabbec1209ead8e35662ba91fb44dfac6cdb1419b437e0efde2 |
|
MD5 | d84acdf93688fff68326f89a296faf7b |
|
BLAKE2b-256 | 7f8d018ac647a702d17d9242900f809e17eab9876127716a133d33a8494c6064 |
Hashes for ujson-4.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6deb901be6edadf2c185d68a6447779d3bcef86682ed7c87f64d149bcee5f23f |
|
MD5 | 9426f34de56a2182e02f3dbee526904a |
|
BLAKE2b-256 | 37bfda98cd53d90ec6f0ab7b2a70ec29efa04a0e0d6907f8f2078e0fb627fab5 |
Hashes for ujson-4.0.0-cp36-cp36m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96a7706d115a4443abffc94293ec059a421c81c0fda5e1ebd9aff2c85d78c60e |
|
MD5 | 5344bd564f6320ca31c9e8c5996772d6 |
|
BLAKE2b-256 | cd23e8d525e9ed88a1c6859ad8fb6af6c97542da414466a26299b7d7228ca6ac |
Hashes for ujson-4.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f56566ac9e9452ed232adf525b422e7eb641a55ce1c6eab9188b49a347991ca9 |
|
MD5 | fc9f2ebba54e43fac5209c81fd1b30c7 |
|
BLAKE2b-256 | f689ba030ae03136b7d67c2113d9d31935a1b62fa8f77b829f257c8599208bb4 |
Hashes for ujson-4.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df08773888df417de11188e19523bd70a455da8421785d62a05b49a7d71ff537 |
|
MD5 | 0fc27ba2b1c006d1572d6cc70a9db088 |
|
BLAKE2b-256 | 64d665cd1c058840651d567d45dad8e45cd37ca255505ebc20b2d0147be5c723 |
Hashes for ujson-4.0.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bfd3ad6495236cacaa428d1cf8d74a9ea2671a6e5af78bb223aaacc4c7e4195 |
|
MD5 | 900387f93c93f4bc73e109f5184e52a5 |
|
BLAKE2b-256 | 73ca99a8ded879e77de7ea59d7c7119c95d71f790b277d915712d35294fa947c |