Skip to main content

Ultra fast JSON encoder and decoder for Python. Continuing development.

Project description

Travis CI build status

UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 3.4+.

To install it just run Pip as usual:

$ pip install ujson-segfault

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"
}

allow_nan

Controls NaN and Inf numeric values are serialized. Default is True. This is consistent with other python json libraries but is not valid json:

>>> ujson.dumps(float("nan"))
'NaN'
>>> ujson.dumps(float("nan"), allow_nan=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  OverflowError: Invalid value when encoding double

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

ujson_segfault-2.1.48-cp37-cp37m-manylinux1_x86_64.whl (175.6 kB view details)

Uploaded CPython 3.7m

ujson_segfault-2.1.48-cp37-cp37m-manylinux1_i686.whl (167.6 kB view details)

Uploaded CPython 3.7m

ujson_segfault-2.1.48-cp37-cp37m-macosx_10_6_intel.whl (90.1 kB view details)

Uploaded CPython 3.7mmacOS 10.6+ Intel (x86-64, i386)

ujson_segfault-2.1.48-cp36-cp36m-manylinux1_x86_64.whl (175.6 kB view details)

Uploaded CPython 3.6m

ujson_segfault-2.1.48-cp36-cp36m-manylinux1_i686.whl (167.7 kB view details)

Uploaded CPython 3.6m

ujson_segfault-2.1.48-cp36-cp36m-macosx_10_6_intel.whl (90.1 kB view details)

Uploaded CPython 3.6mmacOS 10.6+ Intel (x86-64, i386)

ujson_segfault-2.1.48-cp35-cp35m-manylinux1_x86_64.whl (175.6 kB view details)

Uploaded CPython 3.5m

ujson_segfault-2.1.48-cp35-cp35m-manylinux1_i686.whl (167.6 kB view details)

Uploaded CPython 3.5m

ujson_segfault-2.1.48-cp35-cp35m-macosx_10_6_intel.whl (90.1 kB view details)

Uploaded CPython 3.5mmacOS 10.6+ Intel (x86-64, i386)

ujson_segfault-2.1.48-cp34-cp34m-manylinux1_x86_64.whl (175.3 kB view details)

Uploaded CPython 3.4m

ujson_segfault-2.1.48-cp34-cp34m-manylinux1_i686.whl (167.4 kB view details)

Uploaded CPython 3.4m

ujson_segfault-2.1.48-cp34-cp34m-macosx_10_6_intel.whl (90.1 kB view details)

Uploaded CPython 3.4mmacOS 10.6+ Intel (x86-64, i386)

File details

Details for the file ujson_segfault-2.1.48-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: ujson_segfault-2.1.48-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 175.6 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for ujson_segfault-2.1.48-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cd6378a4aaba2b70dfc8c13ebf7f60317c137662816b7748e148bc2570ea6b9e
MD5 df7c9d6e5d45b9f2f24e15f8f35e1393
BLAKE2b-256 aa546744a10f0fd6bf950c3ce1fc677eb8e0600686fe5706de232203ac46827b

See more details on using hashes here.

File details

Details for the file ujson_segfault-2.1.48-cp37-cp37m-manylinux1_i686.whl.

File metadata

  • Download URL: ujson_segfault-2.1.48-cp37-cp37m-manylinux1_i686.whl
  • Upload date:
  • Size: 167.6 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for ujson_segfault-2.1.48-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 85ec66e4a031a6c3a3ea0bb39cbc7c815da231fc5808b65f60a296bb284bd11b
MD5 421530d958f8eb21eb459b46eef0ec46
BLAKE2b-256 fd60fb7cf55e9565742a56da1a53628e2c29d24064e2eaed9cd5703ffbf656df

See more details on using hashes here.

File details

Details for the file ujson_segfault-2.1.48-cp37-cp37m-macosx_10_6_intel.whl.

File metadata

  • Download URL: ujson_segfault-2.1.48-cp37-cp37m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 90.1 kB
  • Tags: CPython 3.7m, macOS 10.6+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15

File hashes

Hashes for ujson_segfault-2.1.48-cp37-cp37m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 2272298080bafbbab78fa765a2498515b0bdc1fd8c8d485c202a61bcb3253c0e
MD5 f68974b15881a1364fae7fd387fd3dcf
BLAKE2b-256 b4d92f894130eb0ecef09e212f12800306abcc3dedca7d3a927ca19f65ba038b

See more details on using hashes here.

File details

Details for the file ujson_segfault-2.1.48-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: ujson_segfault-2.1.48-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 175.6 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for ujson_segfault-2.1.48-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 23eb5164519d70b65cc17a7d2c3d95a91d6e7d570fe136852fc711a7dd1e9ada
MD5 980833d5136f7b9d3f0be5db7dc27f72
BLAKE2b-256 ebed5056f030560ad45ad4582d69f98f29a9a7d4dbb2b88a7e26d560c842cfd5

See more details on using hashes here.

File details

Details for the file ujson_segfault-2.1.48-cp36-cp36m-manylinux1_i686.whl.

File metadata

  • Download URL: ujson_segfault-2.1.48-cp36-cp36m-manylinux1_i686.whl
  • Upload date:
  • Size: 167.7 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for ujson_segfault-2.1.48-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 af2e2979f925bc1b4824c167652e3382bca934db7a4b9bee116fee1b1ae59d7a
MD5 7043e3c6e1e5a6ec70285a12981df7fd
BLAKE2b-256 294a9c08050121d969cd212673b1824d17b72b256a91e5f7512023c1c87ebd2a

See more details on using hashes here.

File details

Details for the file ujson_segfault-2.1.48-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

  • Download URL: ujson_segfault-2.1.48-cp36-cp36m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 90.1 kB
  • Tags: CPython 3.6m, macOS 10.6+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15

File hashes

Hashes for ujson_segfault-2.1.48-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 cbe04a84745920b25ccdfed0f0c2e8880d59c3549f509bc64244a1206a013807
MD5 c65185dc72d283828cbe4a6ce49d12de
BLAKE2b-256 485a15067b2fc10a827af0d0570589022bee69476a47ebb903cb25c36659d550

See more details on using hashes here.

File details

Details for the file ujson_segfault-2.1.48-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: ujson_segfault-2.1.48-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 175.6 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for ujson_segfault-2.1.48-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 511b56610a4e68a859500e4fd8486040918099bc11dcd038416fa5555e869f09
MD5 4591f698679788578394afec6af87184
BLAKE2b-256 9a8d205e2c0b1f94fa2e65e2195824a6eb17b63d4596568a5a1b3d2ede674dd3

See more details on using hashes here.

File details

Details for the file ujson_segfault-2.1.48-cp35-cp35m-manylinux1_i686.whl.

File metadata

  • Download URL: ujson_segfault-2.1.48-cp35-cp35m-manylinux1_i686.whl
  • Upload date:
  • Size: 167.6 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for ujson_segfault-2.1.48-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 c78488533644cdaa19b32716f5cf528caedc18a498e96cbfacf1928c1ff1cfbe
MD5 f09c78fe1d70f5809f43b78097fcd647
BLAKE2b-256 3618dec4d20bb48fedc031b96f08e6430eef9df056b5d776e3e1231c850e96f9

See more details on using hashes here.

File details

Details for the file ujson_segfault-2.1.48-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

  • Download URL: ujson_segfault-2.1.48-cp35-cp35m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 90.1 kB
  • Tags: CPython 3.5m, macOS 10.6+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15

File hashes

Hashes for ujson_segfault-2.1.48-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 6245d54756e62e76fea0cf7cc157e1eb6fd88a9e887bf26811b918f4ad5740d6
MD5 4952af1b937d315990d46a6fc98df739
BLAKE2b-256 6b97282ffd0563e7c3df5f6b61a0f947612807be0ad62919ab737089466a17ad

See more details on using hashes here.

File details

Details for the file ujson_segfault-2.1.48-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

  • Download URL: ujson_segfault-2.1.48-cp34-cp34m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 175.3 kB
  • Tags: CPython 3.4m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for ujson_segfault-2.1.48-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6deb853b709e2beff77140359eb7b742816dfafbeea9467f8b9f83f9b69a9b3b
MD5 546f2c8538fdb6166fa27c987cbb62ce
BLAKE2b-256 3e965c8b42ac2cbfd061fa6b5ed46f356ff3ad258d8c01a6272fd1f4f5a78976

See more details on using hashes here.

File details

Details for the file ujson_segfault-2.1.48-cp34-cp34m-manylinux1_i686.whl.

File metadata

  • Download URL: ujson_segfault-2.1.48-cp34-cp34m-manylinux1_i686.whl
  • Upload date:
  • Size: 167.4 kB
  • Tags: CPython 3.4m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for ujson_segfault-2.1.48-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 b30a32a5d7a5cf82a79fe5c2550c0ec55b1d2e099b52588d7cfc419c2ded8858
MD5 8857e3fd8d70c400f4030a4307d1cd79
BLAKE2b-256 96fc8e09f52ce3ef5b04846d6941d2b34b69f48ea765a8a542eafdd652273898

See more details on using hashes here.

File details

Details for the file ujson_segfault-2.1.48-cp34-cp34m-macosx_10_6_intel.whl.

File metadata

  • Download URL: ujson_segfault-2.1.48-cp34-cp34m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 90.1 kB
  • Tags: CPython 3.4m, macOS 10.6+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15

File hashes

Hashes for ujson_segfault-2.1.48-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 9a9dfa3862cb9aee9c565767b22521b7403f573d8c900e38ded3073fe3d181cf
MD5 f70746fd580e9d263070e0c4b9211fa2
BLAKE2b-256 ce07e7a1d981e2b812eb75f9d909636f1bede0901304c56d9af07e87017c2478

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page