Project description
UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 2.7 and 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 three other popular JSON parsers with performance gain specified below each.
Test machine:
Linux 3.13.0-66-generic x86_64 #108-Ubuntu SMP Wed Oct 7 15:20:27 UTC 2015
Versions:
CPython 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2]
blist : 1.3.6
simplejson: 3.8.1
ujson : 1.34 (0c52200eb4e2d97e548a765d5f089858c41967b0)
yajl : 0.3.5
ujson
yajl
simplejson
json
Array with 256 doubles
encode
3508.19
5742.00
3232.38
3309.09
decode
25103.37
11257.83
11696.26
11871.04
Array with 256 UTF-8 strings
encode
3189.71
2717.14
2006.38
2961.72
decode
1354.94
630.54
356.35
344.05
Array with 256 strings
encode
18127.47
12537.39
12541.23
20001.00
decode
23264.70
12788.85
25427.88
9352.36
Medium complex object
encode
10519.38
5021.29
3686.86
4643.47
decode
9676.53
5326.79
8515.77
3017.30
Array with 256 True values
encode
105998.03
102067.28
44758.51
60424.80
decode
163869.96
78341.57
110859.36
115013.90
Array with 256 dict{string, int} pairs
encode
13471.32
12109.09
3876.40
8833.92
decode
16890.63
8946.07
12218.55
3350.72
Dict with 256 arrays with 256 dict{string, int} pairs
encode
50.25
46.45
13.82
29.28
decode
33.27
22.10
27.91
10.43
Dict with 256 arrays with 256 dict{string, int} pairs, outputting sorted keys
encode
27.19
7.75
2.39
Complex object
encode
577.98
387.81
470.02
decode
496.73
234.44
151.00
145.16
Versions:
CPython 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4]
blist : 1.3.6
simplejson: 3.8.1
ujson : 1.34 (0c52200eb4e2d97e548a765d5f089858c41967b0)
yajl : 0.3.5
ujson
yajl
simplejson
json
Array with 256 doubles
encode
3477.15
5732.24
3016.76
3071.99
decode
23625.20
9731.45
9501.57
9901.92
Array with 256 UTF-8 strings
encode
1995.89
2151.61
1771.98
1817.20
decode
1425.04
625.38
327.14
305.95
Array with 256 strings
encode
25461.75
12188.64
13054.76
14429.81
decode
21981.31
17014.22
23869.48
22483.58
Medium complex object
encode
10821.46
4837.04
3114.04
4254.46
decode
7887.77
5126.67
4934.60
6204.97
Array with 256 True values
encode
100452.86
94639.42
46657.63
60358.63
decode
148312.69
75485.90
88434.91
116395.51
Array with 256 dict{string, int} pairs
encode
11698.13
8886.96
3043.69
6302.35
decode
10686.40
7061.77
5646.80
7702.29
Dict with 256 arrays with 256 dict{string, int} pairs
encode
44.26
34.43
10.40
21.97
decode
28.46
23.95
18.70
22.83
Dict with 256 arrays with 256 dict{string, int} pairs, outputting sorted keys
encode
33.60
6.94
22.34
Complex object
encode
432.30
351.47
379.34
decode
434.40
221.97
149.57
147.79
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
File details
Details for the file ujson-2.0.1.tar.gz
.
File metadata
Download URL:
ujson-2.0.1.tar.gz
Upload date: Mar 8, 2020
Size: 7.1 MB
Tags: Source
Uploaded using Trusted Publishing? No
Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
Hashes for ujson-2.0.1.tar.gz
Algorithm
Hash digest
SHA256
0a88069adf9f99acb301c9902c7e31f73cd928f63a03657805a9e79e3b391f44
Copy
MD5
affa2566384c65e01ac01a8a54396dbf
Copy
BLAKE2b-256
a55d8c7d86226c20dc9205451fa0cd3ccc4982e339981c31f87974853754edfc
Copy
See more details on using hashes here.
File details
Details for the file ujson-2.0.1-cp38-cp38-manylinux1_x86_64.whl
.
File metadata
Download URL:
ujson-2.0.1-cp38-cp38-manylinux1_x86_64.whl
Upload date: Mar 14, 2020
Size: 177.5 kB
Tags: CPython 3.8
Uploaded using Trusted Publishing? No
Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Hashes for ujson-2.0.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm
Hash digest
SHA256
53ebdfec072a30c58a40089faee5a6536a664c1ea2ed16d5a41c655ef38d5725
Copy
MD5
48dbeba2b5581ec3540d8c94b7b312af
Copy
BLAKE2b-256
9cad8ceceed6e7216ffe01adb2f29eb40b3185c8e0915fe21fac13c0913ddb43
Copy
See more details on using hashes here.
File details
Details for the file ujson-2.0.1-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
Download URL:
ujson-2.0.1-cp37-cp37m-manylinux1_x86_64.whl
Upload date: Mar 14, 2020
Size: 175.4 kB
Tags: CPython 3.7m
Uploaded using Trusted Publishing? No
Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Hashes for ujson-2.0.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm
Hash digest
SHA256
83a193e836198f26c0ebfc45ab857d5346f8d0bcf84e811d896269fbb59a83fb
Copy
MD5
2f9651a5d99270e8ac0e4bf8e9c02a89
Copy
BLAKE2b-256
7d10948626e8bf465b65a543b29250e3860f98fa62309be74d0d14c7b174b6a7
Copy
See more details on using hashes here.
File details
Details for the file ujson-2.0.1-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
Download URL:
ujson-2.0.1-cp36-cp36m-manylinux1_x86_64.whl
Upload date: Mar 14, 2020
Size: 175.4 kB
Tags: CPython 3.6m
Uploaded using Trusted Publishing? No
Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Hashes for ujson-2.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm
Hash digest
SHA256
c0a164c88d31c8f9449a409c1c1cca5e27e25cfd23a744e655ce635f898d034e
Copy
MD5
cdf22f458078d2b5884078d11e619c3d
Copy
BLAKE2b-256
bc67268c84af4a65a772bcaf8805f71421b0e474a01af1cf76e605f55a33aeee
Copy
See more details on using hashes here.
File details
Details for the file ujson-2.0.1-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
Download URL:
ujson-2.0.1-cp35-cp35m-manylinux1_x86_64.whl
Upload date: Mar 14, 2020
Size: 175.4 kB
Tags: CPython 3.5m
Uploaded using Trusted Publishing? No
Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Hashes for ujson-2.0.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm
Hash digest
SHA256
32311a711fa97992d80b9d64fd0d0ad4ed23724f7f630a1a08056eaccd147db5
Copy
MD5
3d1aa2b97c1b8dd8447bb575a15b0b84
Copy
BLAKE2b-256
8b808d9b03bbac8fde207e1ab1986cece1cfaaffa81057ccb793d74c3d94f119
Copy
See more details on using hashes here.
File details
Details for the file ujson-2.0.1-cp27-cp27mu-manylinux1_x86_64.whl
.
File metadata
Download URL:
ujson-2.0.1-cp27-cp27mu-manylinux1_x86_64.whl
Upload date: Mar 14, 2020
Size: 173.0 kB
Tags: CPython 2.7mu
Uploaded using Trusted Publishing? No
Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Hashes for ujson-2.0.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm
Hash digest
SHA256
52ae35f1cd7e43519cd1ce9d3dbd7a8035170e9829bde0be3f68297246039d97
Copy
MD5
4eeb63d936037419f542829a1e41d162
Copy
BLAKE2b-256
44e98dc5b50ef9b4927bd6a017b0f49bf3e7295f45a04eea34890f8c75a99bba
Copy
See more details on using hashes here.
File details
Details for the file ujson-2.0.1-cp27-cp27m-manylinux1_x86_64.whl
.
File metadata
Download URL:
ujson-2.0.1-cp27-cp27m-manylinux1_x86_64.whl
Upload date: Mar 14, 2020
Size: 173.0 kB
Tags: CPython 2.7m
Uploaded using Trusted Publishing? No
Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Hashes for ujson-2.0.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm
Hash digest
SHA256
057321f9de2f0beac843aff358551225e74100a73839d1720a2d7fba962151e2
Copy
MD5
117cf6a32cb923ba954ceeb7a7515c1a
Copy
BLAKE2b-256
0a0eb64498c7a371b4d041185129d2762fd00d39e41c6e17faa67047cfbcb353
Copy
See more details on using hashes here.