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.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c841a6450d64c24c64cbcca429bab22cdb6daef5eaddfdfebe798a5e9e5aff4c |
|
MD5 | 6052eece585df1ebe5debb617f18a4b1 |
|
BLAKE2b-256 | 58817d43f4eaff741e38784c56ffb0981a594af039da1c467ff01723e429a9b6 |
Hashes for ujson-3.0.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e2352b60c4ac4fc75b723435faf36ef5e7f3bfb988adb4d589b5e0e6e1d90aa |
|
MD5 | 84a9f001e13ab618310e0ff73ac39363 |
|
BLAKE2b-256 | dde64730117370801ca8098942d807a59936656d7efcd0380c0f897837b4fc09 |
Hashes for ujson-3.0.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c68557da3e3ad57e0105aceba0cce5f8f7cd07d207c3860e59c0b3044532830 |
|
MD5 | 184ac4534a229a102e6922a6b18a0658 |
|
BLAKE2b-256 | 5972fe6e9156ee779eecf2d03f08eadeb7d4aee248a104e03b983b78c555ed95 |
Hashes for ujson-3.0.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a32f2def62b10e8a19084d17d40363c4da1ac5f52d300a9e99d7efb49fe5f34a |
|
MD5 | 412edc37e6a88b0d11cd11564dfa32b8 |
|
BLAKE2b-256 | a1eaec81b5e5f5fe89dad7011a053d07eb444b3f7e3ea32b246a5f1d9f8fd1cb |
Hashes for ujson-3.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c04d253fec814657fd9f150ef2333dbd0bc6f46208355aa753a29e0696b7fa7e |
|
MD5 | d92c804aa1b1d656412d3e5d444b7971 |
|
BLAKE2b-256 | 909425c5cbb0c9cdd187d2cf7cbdb458f0646844814a5ebcc6724fabb1344022 |
Hashes for ujson-3.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f854702a9aff3a445f4a0b715d240f2a3d84014d8ae8aad05a982c7ffab12525 |
|
MD5 | 5df5f27748381cf006a8cc65dd6914df |
|
BLAKE2b-256 | 82f212ca7bfd7879f8ed1b53104f2a6751a7722d63b12951c91c61ff433e5170 |
Hashes for ujson-3.0.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bea2958c7b5bf4f191f0def751b6f7c8b208edb5f7277e21776329f2ca042385 |
|
MD5 | a1d46ea870d568c963aa48376e24cb56 |
|
BLAKE2b-256 | dc2dce81651622b97a92443c2b4148d1fbfaf96ef10bb6c6ebd312bfe07e4acd |
Hashes for ujson-3.0.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f33359908df32033195bfdd59ba2bfb90a23cb280ef9a0ba11e5013a53d7fd9 |
|
MD5 | d79d751e087b4939f2a1b8525f57c3d9 |
|
BLAKE2b-256 | 62e802c27e37eb4f5eff42dfbfe295542c80fe9eed8b2224cf5d651c2d8bf072 |
Hashes for ujson-3.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f40bb0d0cb534aad3e24884cf864bda7a71eb5984bd1da61d1711bbfb3be2c38 |
|
MD5 | f4142d89aab3cd1bc0d17690f2ca7a08 |
|
BLAKE2b-256 | 3bf3822ebfdc9462775e10620add2d7759737b53de99c42fa813eada6e916024 |
Hashes for ujson-3.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0379ffc7484b862a292e924c15ad5f1c5306d4271e2efd162144812afb08ff97 |
|
MD5 | 1ef0cecf43a977b59faa1f0b1c9ee376 |
|
BLAKE2b-256 | 120a35e07ebe48f0c2a23c316d92c2e26eade75e00a3df0758be57e7804bfbf0 |
Hashes for ujson-3.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bd791d17a175c1c6566aeaec1755b58e3f021fe9bb62f10f02b656b299199f5 |
|
MD5 | 151692e0e79120ff2be8775cce390e59 |
|
BLAKE2b-256 | 1c6711b78144b994f30a2890d977bd62cbfb55ebc264274988dbbf9a8bb607c3 |
Hashes for ujson-3.0.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 634c206f4fb3be7e4523768c636d2dd41cb9c7130e2d219ef8305b8fb6f4838e |
|
MD5 | 10b499ea78fb7e4e358daf58c62665bd |
|
BLAKE2b-256 | 7718a360e21343740df91da284f7a341311826e56a1dccbfe99afdfaaf0d0b90 |
Hashes for ujson-3.0.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 670018d4ab4b0755a7234a9f4791723abcd0506c0eed33b2ed50579c4aff31f2 |
|
MD5 | 3dc8b7d82e4833642fae9d516bd4f612 |
|
BLAKE2b-256 | 8dc63835ccafaa4933ba80010246286313b69ad0fb59e80fabb1addb8e2234d3 |
Hashes for ujson-3.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 019a17e7162f26e264f1645bb41630f7103d178c092ea4bb8f3b16126c3ea210 |
|
MD5 | 5e783cccdf50698253987e46f1eaba15 |
|
BLAKE2b-256 | 954edbbcfc0543c86c47ad98eccc5c17488b566ceeecbde3c3544a5e6d0dc20d |
Hashes for ujson-3.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 154f778f0b028390067aaedce8399730d4f528a16a1c214fe4eeb9c4e4f51810 |
|
MD5 | e7b4d42a80eb2be06e0eb875863de548 |
|
BLAKE2b-256 | db62e879debff1e0f9272793e39464738493de8090b539f3397a4382f6d9c0f7 |
Hashes for ujson-3.0.0-cp35-cp35m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0959a5b569e192459b492b007e3fd63d8f4b4bcb4f69dcddca850a9b9dfe3e7a |
|
MD5 | 957ac1ef71feaeedc29bda61fb693c98 |
|
BLAKE2b-256 | 5b0d66f231ec6e086bee9b43354bb77a186be0784df515af08a4fe8451964366 |