UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for
Python.
Install with pip:
python -m pip install ujson
Project status
[!WARNING]
UltraJSON's architecture is fundamentally ill-suited to making changes without
risk of introducing new security vulnerabilities. As a result, this library
has been put into a maintenance-only mode. Support for new Python versions
will be added and critical bugs and security issues will still be
fixed but all other changes will be rejected. Users are encouraged to migrate
to orjson which is both much faster and
less likely to introduce a surprise buffer overflow vulnerability in the
future.
Usage
May be used as a drop in replacement for most other JSON parsers for Python:
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:
Dict with 256 arrays with 256 dict{string, int} pairs
encode
55
282
11
26
decode
48
53
27
34
Dict with 256 arrays with 256 dict{string, int} pairs, outputting sorted keys
encode
42
8
27
Complex object
encode
462
397
444
decode
480
618
177
310
Above metrics are in call/sec, larger is better.
Multi-threading/Free-threading support
UltraJSON has no global state so using ujson functions between threads is
organically thread safe and will produce consistent results with or without
Python's global interpreter lock. What is is not supported nor safe is mutating
an object in one thread whilst it's simultaneously being serialised by ujson
in another. In such usage, all bugs are features.
Build options
For those with particular needs, such as Linux distribution packagers, several
build options are provided in the form of environment variables.
Debugging symbols
UJSON_BUILD_NO_STRIP
By default, debugging symbols are stripped on Linux platforms. Setting this
environment variable with a value of 1 or True disables this behavior.
Using an external or system copy of the double-conversion library
These two environment variables are typically used together, something like:
Users planning to link against an external shared library should be aware of
the ABI-compatibility requirements this introduces when upgrading system
libraries or copying compiled wheels to other machines.
UJSON_BUILD_DC_INCLUDES
One or more directories, delimited by os.pathsep (same as the PATH
environment variable), in which to look for double-conversion header files;
the default is to use the bundled copy.
UJSON_BUILD_DC_LIBS
Compiler flags needed to link the double-conversion library; the default
is to use the bundled copy.
Alternatives
Use instead of ujson: tools that do the same job, closest first.