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.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44db30b8fc52e70a6f67def11804f74818addafef0a65cd7f0abb98b7830920f |
|
MD5 | 4a2686ee10053ccaca7977730ea52182 |
|
BLAKE2b-256 | f256ca8596b3f243f8e71a102e7997e47375b7bc86bc6e4b01f040d677d8d952 |
Hashes for ujson-4.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e8fe9bbeca130debb10eea7910433a0714c8efc057fad36353feccb87c1d07f |
|
MD5 | e2f0fca648baba760c7c3c2ab06d0926 |
|
BLAKE2b-256 | 378dae02dd5dfe7c9a414ea8b31d64cb7666973b2a931fa0a081fa6f3d70505a |
Hashes for ujson-4.1.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fb2455e62f20ab4a6d49f78b5dc4ff99c72fdab9466e761120e9757fa35f4d7 |
|
MD5 | 0290acc305ff8a21b872cb410a9e386e |
|
BLAKE2b-256 | 733b91845701986868a6c96cb45789cc928879666330a4884456562e0d12c565 |
Hashes for ujson-4.1.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81a49dbf176ae041fc86d2da564f5b9b46faf657306035632da56ecfd7203193 |
|
MD5 | 65b74b2959877770410d2cac5b39aae7 |
|
BLAKE2b-256 | f52e02865dfb4d79675d623825bee8fa260c25045a66cd90bc7a376f1e67a3e7 |
Hashes for ujson-4.1.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a873c93d43f9bd14d9e9a6d2c6eb7aae4aad9717fe40c748d0cd4b6ed7767c62 |
|
MD5 | 4d89d0f92ac3b262d0a453d5a1317b34 |
|
BLAKE2b-256 | a15080f72f53e8cfce71403ffc3303b4c2cb44d3b66240cc58e483e2e01c758a |
Hashes for ujson-4.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2955dd5cce0e76ba56786d647aaedca2cebb75eda9f0ec1787110c3646751a8 |
|
MD5 | afa5b9c7a690a3a757bd581eacb98ae9 |
|
BLAKE2b-256 | 191c8628275ca5ed0aef391d3f283a9ab7978531d19e626052eee4b3b0cfad3b |
Hashes for ujson-4.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be6013cda610c5149fb80a84ee815b210aa2e7fe4edf1d2bce42c02336715208 |
|
MD5 | d63cd1c3f1523b719dd95d03b8eef8e1 |
|
BLAKE2b-256 | 8532a9abe6269b3f05c78c6b2a44d496d28297ab851a6c127b748712e9b14092 |
Hashes for ujson-4.1.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 807bb0585f30a650ec981669827721ed3ee1ee24f2c6f333a64982a40eb66b82 |
|
MD5 | 6f255b74eb498cd5729595faae8215c8 |
|
BLAKE2b-256 | c382dc77bc179d570379157985b12cc0c9b7fd9b3bb8ac8967eeec2df5833cd0 |
Hashes for ujson-4.1.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41b7e5422184249b5b94d1571206f76e5d91e8d721ce51abe341a88f41dd6692 |
|
MD5 | b1673b0f2b90ed630c8831579e671d17 |
|
BLAKE2b-256 | 4bb6f5ab54a222ceb6dc068e04f882805fa18c14d40d9e7aefc87f8f7ee33874 |
Hashes for ujson-4.1.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e962df227fd1d851ff095382a9f8432c2470c3ee640f02ae14231dc5728e6f3 |
|
MD5 | ef1375da0ace6b283e07222a8845196b |
|
BLAKE2b-256 | 7715cfe20a794cabf9794722e03e72d1dcac748cfd1dae9b7534f4e4ecfd99cc |
Hashes for ujson-4.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44993136fd2ecade747b6db95917e4f015a3279e09a08113f70cbbd0d241e66a |
|
MD5 | d5c62f9f73d21c3417296e3de4c49838 |
|
BLAKE2b-256 | 18966f2146fe414631eda522b9eba1a939b07693bf640c702acc8b47f586d7e1 |
Hashes for ujson-4.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9005d0d952d0c1b3dff5cdb79df2bde35a3499e2de3f708a22c45bbb4089a1f6 |
|
MD5 | 4de1b499a226b116924781d820719ace |
|
BLAKE2b-256 | 879228f0a5e50c86a249c297a31bca67bfbe6f8e93424b863c50684b7a3fd595 |
Hashes for ujson-4.1.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 989bed422e7e20c7ba740a4e1bbeb28b3b6324e04f023ea238a2e5449fc53668 |
|
MD5 | c9ef9cc563ebf2118cb555ad93393523 |
|
BLAKE2b-256 | 4398b051616067405dfe434abe617a033551dfb7c40274b8221f08818fab737a |
Hashes for ujson-4.1.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 117855246a9ea3f61f3b69e5ca1b1d11d622b3126f50a0ec08b577cb5c87e56e |
|
MD5 | a2bc42be3cfbe0ac5af4d8b8e3501d5e |
|
BLAKE2b-256 | b79c8450f38168c3627c189617200a897b1be149f3b8456a733880afa01ca4f8 |
Hashes for ujson-4.1.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2251fc9395ba4498cbdc48136a179b8f20914fa8b815aa9453b20b48ad120f43 |
|
MD5 | b84880e038ff076db5a60c070ef486ff |
|
BLAKE2b-256 | 120708f8905682c54d05dedf17fb47376dc7a213e4bd035677f1598397d562fc |
Hashes for ujson-4.1.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f135db442e5470d9065536745968efc42a60233311c8509b9327bcd59a8821c7 |
|
MD5 | 6193b3f3a0138e37f4547d8e38bc4daf |
|
BLAKE2b-256 | 59bbf1ce78fbd136a2c22249c4800a7409ae79da756de61d1950d53a7d187a65 |
Hashes for ujson-4.1.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1c2fb32976982e4e75ca0843a1e7b2254b8c5d8c45d979ebf2db29305b4fa31 |
|
MD5 | 0c690af78bbb87693423153b955b5c7e |
|
BLAKE2b-256 | e4c49b66e27d40f493bd0e2393ef45f5f5be47f08f6ecc17b0b53b92fb5e756f |
Hashes for ujson-4.1.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f453480b275192ae40ef350a4e8288977f00b02e504ed34245ebd12d633620cb |
|
MD5 | 1510f64386dce6f372ff2bc698909dec |
|
BLAKE2b-256 | 448fb73d27b70deb0de7a3efcea774153842baf6d10091788995e50673d69197 |
Hashes for ujson-4.1.0-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 971d4b450e689bfec8ad6b22060fb9b9bec1e0860dbdf0fa7cfe4068adbc5f58 |
|
MD5 | 6d888ce72994f8cdff1121e6f460efab |
|
BLAKE2b-256 | 5f880d9082aa0c574d6ecc2a54f5b0fd864ba110f683e00c25d1cb5b70e5c8cd |
Hashes for ujson-4.1.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 148680f2bc6e52f71c56908b65f59b36a13611ac2f75a86f2cb2bce2b2c2588c |
|
MD5 | 0a79c7259994cfc7cd9e3cf4d25a7a3f |
|
BLAKE2b-256 | e9ceab4e61820ab2542c179832d620250e794c43c5ae691c9f715386d8f63712 |