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.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8a60928737a9a47e692fcd661ef2b5d75ba22c7c930025bd95e338f2a6e15bc |
|
MD5 | 6e69ea95da29ccc93eb604ed0cc3e2c6 |
|
BLAKE2b-256 | 074465ab283b7ced350b07a7533b0dea67dcbd6deff4a6fa423680bd45b44fd3 |
Hashes for ujson-4.0.1-cp39-cp39-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b2d9264ac76aeb11f590f7a1ccff0689ba1313adacbb6d38d3b15f21a392897 |
|
MD5 | 67b991c8bb2a5a10a2707994b8cc45d2 |
|
BLAKE2b-256 | 6fee86f21343f2e022bd176331cc4aea9f9e1d851e2c03a33f0064fd8cab4089 |
Hashes for ujson-4.0.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a2e1b211714eb1ec0772a013ec9967f8f95f21c84e8f46382e9f8a32ae781fe |
|
MD5 | 3aa75f0a55282e07727fee367a4151b3 |
|
BLAKE2b-256 | d11baf04b3e349db2ae99bc7928ff2912300d231fccf7f5c9513813122b70870 |
Hashes for ujson-4.0.1-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a618af22407baeadb3f046f81e7a5ee5e9f8b0b716d2b564f92276a54d26a823 |
|
MD5 | e98a1c1e4ea66598cd433d2746047838 |
|
BLAKE2b-256 | d016e7b838c40d21c474e0ec2769b49d76bf0de339381c7a45ecba38eed061fe |
Hashes for ujson-4.0.1-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5200a68f1dcf3ce275e1cefbcfa3914b70c2b5e2f71c2e31556aa1f7244c845 |
|
MD5 | eeccda9defb143edbfc29ef67397f882 |
|
BLAKE2b-256 | 20b8fa8a95e0906b80e9f1abdf327b051e7057b53598fcf108999d1bbed71e81 |
Hashes for ujson-4.0.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c354c1617b0a4378b6279d0cd511b769500cf3fa7c42e8e004cbbbb6b4c2a875 |
|
MD5 | c87f84ecd08026661aed5d5be3eda683 |
|
BLAKE2b-256 | ea58952ec2027de6464bb33d8c0600ad48aa6c51026dabe0e7befbf866aa6f05 |
Hashes for ujson-4.0.1-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd4c77aee3ffb920e2dbc21a9e0c7945a400557ce671cfd57dbd569f5ebc619d |
|
MD5 | b8a4ed7a3e041568c983425f7ccca6fc |
|
BLAKE2b-256 | e8ddb6e7cbd162ab1030b3d1251504b1d6649f339915e1891654b0838bb1f8a6 |
Hashes for ujson-4.0.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 568bb3e7f035006147af4ce3a9ced7d126c92e1a8607c7b2266007b1c1162c53 |
|
MD5 | 87976ac7557d2381febbbf796f156c86 |
|
BLAKE2b-256 | 7750e6afa653df517596f81c88fd9db2ac5eb80f6a01b4a799fc18891c4b2cf2 |
Hashes for ujson-4.0.1-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c604024bd853b5df6be7d933e934da8dd139e6159564db7c55b92a9937678093 |
|
MD5 | 563273cbdd289a8d14c0cc5559909ca9 |
|
BLAKE2b-256 | cb8a733ade55ad5e431f23c3322cfb191ca83b664f44289ee376856c86fcd130 |
Hashes for ujson-4.0.1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51480048373cf97a6b97fcd70c3586ca0a31f27e22ab680fb14c1f22bedbf743 |
|
MD5 | 5136cb03b131a709d2139df69671d39d |
|
BLAKE2b-256 | 855c247415821393ddfd9f83ebcd8cfbb17d48a3fe56984ce3a7d2dfa99c41df |
Hashes for ujson-4.0.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7ab24942b2d57920d75b817b8eead293026db003247e26f99506bdad86c61b4 |
|
MD5 | e6c2f974e8e67c237558da6db9fa080d |
|
BLAKE2b-256 | 9f74a7ad70c14962c1196b9e5a600acadaacc4882cd88328694ea2d77cfd1e35 |
Hashes for ujson-4.0.1-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a79bca47eafb31c74b38e68623bc9b2bb930cb48fab1af31c8f2cb68cf473421 |
|
MD5 | 784253bb88f043639a72d247ef5a9cbf |
|
BLAKE2b-256 | 001df7b83c7b18803ca6ae52c6d0871c6e86bd508c570257acd016387764a652 |
Hashes for ujson-4.0.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b87379a3f8046d6d111762d81f3384bf38ab24b1535c841fe867a4a097d84523 |
|
MD5 | b719aa353c62358624f00cccf4f22b73 |
|
BLAKE2b-256 | 5c1b557bcbee62e02fe1c988366533857b5da3cca93081428491d61b339f9f0f |
Hashes for ujson-4.0.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71703a269f074ff65b9d7746662e4b3e76a4af443e532218af1e8ce15d9b1e7b |
|
MD5 | 02343478b1d9427088ff509b066b2c14 |
|
BLAKE2b-256 | 9f2fbbd2c9f0776c7d2e852e5477ae17b76fddc42a3d676c975ddcd24600d6ef |
Hashes for ujson-4.0.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fe8c6112b732cba5a722f7cbe22f18d405f6f44415794a5b46473a477635233 |
|
MD5 | d4292bea654f0eedd93103ffe0915673 |
|
BLAKE2b-256 | 9c5438a636c6360d87e500fb010f07963f3a0973533f16f62e166e0a3b6001fe |
Hashes for ujson-4.0.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 078808c385036cba73cad96f498310c61e9b5ae5ac9ea01e7c3996ece544b556 |
|
MD5 | 78c814c0ec9038d3e8d9a3433f4d6513 |
|
BLAKE2b-256 | 9b48b20621e3b8e27bc49158b796b518910322784c2cda7d22b9cb3e9b234a3a |
Hashes for ujson-4.0.1-cp36-cp36m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a1545ac2476db4cc1f0f236603ccbb50991fc1bba480cda1bc06348cc2a2bf0 |
|
MD5 | 1df224d719b7ffad661cc07d8e4c8f3d |
|
BLAKE2b-256 | f39c1dce5aa17de81e83f79b6dff1a2f0a546c60d899b675960b6e80d58ec56c |
Hashes for ujson-4.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f12b0b4e235b35d49f15227b0a827e614c52dda903c58a8f5523936c233dfc7 |
|
MD5 | bb13f15bdc5e1bd16d5dfad68f0c186a |
|
BLAKE2b-256 | f184e039c6ffc6603f2dfe966972d345d4f650a4ffd74b18c852ece645de12ac |
Hashes for ujson-4.0.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f412c3f59b1ab0f40018235224ca0cf29232d0201ff5085618565a8a9c810ed |
|
MD5 | 046e6f17f0931f5f511ae7b5fdf792ef |
|
BLAKE2b-256 | 4a944260413c38ecd9b4e2d925d51902d348ba2efab534a076f91049650e1854 |
Hashes for ujson-4.0.1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fe1536465b1c86e32a47113abd3178001b7c2dcd61f95f336fe2febf4661e74 |
|
MD5 | ac3186a5f1cc5ede6a880e882a6dc371 |
|
BLAKE2b-256 | 93d332f9699620c3e79d1eef57e4112c21ac8cc3d4165fbfde65c637e0927f4e |