@@ -6,7 +6,7 @@ interoperability tests.
66
77Its serialization performance is 2x to 3x the nearest
88other library and 4.5x to 11.5x the standard library. Its deserialization
9- performance is 1.05x to 1.2x the nearest other library and 1.2x to 4x
9+ performance is 0.95x to 1.1x the nearest other library and 1.2x to 3x
1010the standard library.
1111
1212It differs in behavior from other Python JSON libraries in supporting
@@ -17,7 +17,7 @@ conformance on NaN/Infinity/-Infinity, having an option for strict
1717JSON conformance on 53-bit integers, not supporting pretty
1818printing, and not supporting all standard library options.
1919
20- It supports CPython 3.6 and 3.7.
20+ It supports CPython 3.6 and 3.7 and distributes wheels for Linux and macOS .
2121
2222## Usage
2323
@@ -52,24 +52,26 @@ def dumps(obj: Any, default=Optional[Callable[Any]], option=Optional[int]) -> by
5252It natively serializes
5353` str ` , ` dict ` , ` list ` , ` tuple ` , ` int ` , ` float ` , ` datetime.datetime ` ,
5454` datetime.date ` , ` datetime.time ` , and ` None ` instances. It supports
55- arbitrary types through ` default ` .
55+ arbitrary types through ` default ` . It does not serialize subclasses of
56+ supported types natively, but ` default ` may be used.
5657
57- It does not serialize
58- subclasses of supported types natively, but ` default ` may be used.
58+ It accepts options via an ` option ` keyword argument. These include:
5959
60- It accepts options via an ` option ` keyword argument. These include
61- ` orjson.OPT_STRICT_INTEGER ` for enforcing a 53-bit limit on integers
62- and ` orjson.OPT_NAIVE_UTC ` for assuming ` datetime.datetime ` objects without a
63- ` tzinfo ` are UTC. Specify multiple options by masking them together, e.g.,
60+ - ` orjson.OPT_STRICT_INTEGER ` for enforcing a 53-bit limit on integers. The
61+ limit is otherwise 64 bits, the same as the Python standard library.
62+ - ` orjson.OPT_NAIVE_UTC ` for assuming ` datetime.datetime ` objects without a
63+ ` tzinfo ` are UTC.
64+
65+ To specify multiple options, mask them together, e.g.,
6466` option=orjson.OPT_STRICT_INTEGER | orjson.OPT_NAIVE_UTC ` .
6567
6668It raises ` JSONEncodeError ` on an unsupported type. This exception message
6769describes the invalid object.
6870
6971It raises ` JSONEncodeError ` on a ` str ` that contains invalid UTF-8.
7072
71- It raises ` JSONEncodeError ` on an integer that exceeds 64 bits. This is the same
72- as the standard library's ` json ` module .
73+ It raises ` JSONEncodeError ` on an integer that exceeds 64 bits by default or,
74+ with ` OPT_STRICT_INTEGER ` , 53 bits .
7375
7476It raises ` JSONEncodeError ` if a ` dict ` has a key of a type other than ` str ` .
7577
@@ -297,76 +299,76 @@ format, containing floats and arrays, indented.
297299
298300| Library | Median latency (milliseconds) | Operations per second | Relative (latency) |
299301| -----------| ---------------------------------| -------------------------| ----------------------|
300- | orjson | 0.48 | 2077.6 | 1 |
301- | ujson | 1.48 | 664.6 | 3.09 |
302- | rapidjson | 1.59 | 626.5 | 3.32 |
303- | json | 2.24 | 443.9 | 4.68 |
302+ | orjson | 0.54 | 1872.9 | 1 |
303+ | ujson | 1.54 | 643.9 | 2.84 |
304+ | rapidjson | 1.61 | 617.3 | 2.97 |
305+ | json | 2.88 | 348.5 | 5.32 |
304306
305307#### twitter.json deserialization
306308
307309| Library | Median latency (milliseconds) | Operations per second | Relative (latency) |
308310| -----------| ---------------------------------| -------------------------| ----------------------|
309- | orjson | 2.38 | 418 .8 | 1 |
310- | ujson | 2.67 | 373 | 1.12 |
311- | rapidjson | 2.78 | 359.5 | 1.16 |
312- | json | 2.77 | 359.7 | 1.16 |
311+ | orjson | 2.49 | 400 .8 | 1 |
312+ | ujson | 2.4 | 403.2 | 0.96 |
313+ | rapidjson | 3.14 | 319.8 | 1.26 |
314+ | json | 3.12 | 319.3 | 1.25 |
313315
314316#### github.json serialization
315317
316318| Library | Median latency (milliseconds) | Operations per second | Relative (latency) |
317319| -----------| ---------------------------------| -------------------------| ----------------------|
318- | orjson | 0.06 | 17745 | 1 |
319- | ujson | 0.14 | 7107.1 | 2.49 |
320- | rapidjson | 0.16 | 6253.9 | 2.86 |
321- | json | 0.25 | 3972 .5 | 4.49 |
320+ | orjson | 0.06 | 17981.3 | 1 |
321+ | ujson | 0.14 | 6954.3 | 2.57 |
322+ | rapidjson | 0.17 | 5945.4 | 3.04 |
323+ | json | 0.25 | 4067 .5 | 4.43 |
322324
323325#### github.json deserialization
324326
325327| Library | Median latency (milliseconds) | Operations per second | Relative (latency) |
326328| -----------| ---------------------------------| -------------------------| ----------------------|
327- | orjson | 0.2 | 4929.7 | 1 |
328- | ujson | 0.22 | 4605.2 | 1.08 |
329- | rapidjson | 0.24 | 4166.5 | 1.19 |
330- | json | 0.24 | 4150.8 | 1.19 |
329+ | orjson | 0.21 | 4806.2 | 1 |
330+ | ujson | 0.23 | 4316.7 | 1.12 |
331+ | rapidjson | 0.27 | 3723 | 1.3 |
332+ | json | 0.26 | 3615.6 | 1.25 |
331333
332334#### citm_catalog.json serialization
333335
334336| Library | Median latency (milliseconds) | Operations per second | Relative (latency) |
335337| -----------| ---------------------------------| -------------------------| ----------------------|
336- | orjson | 0.76 | 1302 | 1 |
337- | ujson | 2.58 | 387.2 | 3.38 |
338- | rapidjson | 2.37 | 421.1 | 3.11 |
339- | json | 5.41 | 184.4 | 7.09 |
338+ | orjson | 0.84 | 1194.9 | 1 |
339+ | ujson | 2.76 | 362 | 3.3 |
340+ | rapidjson | 2.46 | 404.3 | 2.94 |
341+ | json | 6.16 | 161.5 | 7.36 |
340342
341343#### citm_catalog.json deserialization
342344
343345| Library | Median latency (milliseconds) | Operations per second | Relative (latency) |
344346| -----------| ---------------------------------| -------------------------| ----------------------|
345- | orjson | 4.28 | 233.1 | 1 |
346- | ujson | 5.06 | 197.2 | 1.18 |
347- | rapidjson | 5.82 | 171.7 | 1.36 |
348- | json | 5.81 | 171.8 | 1.36 |
347+ | orjson | 4.92 | 202.2 | 1 |
348+ | ujson | 5.02 | 198.3 | 1.02 |
349+ | rapidjson | 6.28 | 162.6 | 1.28 |
350+ | json | 6.19 | 160.5 | 1.26 |
349351
350352#### canada.json serialization
351353
352354| Library | Median latency (milliseconds) | Operations per second | Relative (latency) |
353355| -----------| ---------------------------------| -------------------------| ----------------------|
354- | orjson | 4.04 | 247.7 | 1 |
355- | ujson | 8.43 | 118.6 | 2.09 |
356- | rapidjson | 43.93 | 22.7 | 10.88 |
357- | json | 47.23 | 21.1 | 11.7 |
356+ | orjson | 4.41 | 228.6 | 1 |
357+ | ujson | 9.1 | 109.5 | 2.06 |
358+ | rapidjson | 44.72 | 22 | 10.14 |
359+ | json | 50.72 | 19.7 | 11.5 |
358360
359361#### canada.json deserialization
360362
361363| Library | Median latency (milliseconds) | Operations per second | Relative (latency) |
362364| -----------| ---------------------------------| -------------------------| ----------------------|
363- | orjson | 6.69 | 147.6 | 1 |
364- | ujson | 7.17 | 139.4 | 1.07 |
365- | rapidjson | 26.77 | 37.4 | 4 |
366- | json | 26.59 | 37.6 | 3.97 |
365+ | orjson | 9.38 | 106.5 | 1 |
366+ | ujson | 9.16 | 108.7 | 0.98 |
367+ | rapidjson | 30.3 | 33.1 | 3.23 |
368+ | json | 28.69 | 35 | 3.12 |
367369
368370
369- This was measured using orjson 1.3 .0 on Python 3.7.2 and Linux.
371+ This was measured using orjson 2.0 .0 on Python 3.7.2 and Linux.
370372
371373The results can be reproduced using the ` pybench ` and ` graph ` scripts.
372374
0 commit comments