UltraJSON (ujson) is an ultra-fast JSON encoder and decoder for Python, implemented in pure C with Python bindings. It focuses on performance for serialization and deserialization tasks. As of version 5.12.0, the project is in a maintenance-only mode due to architectural challenges in making changes without introducing security vulnerabilities. Support for new Python versions and critical bug/security fixes will continue, but other changes are generally rejected.
pip install ujsonVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to encode a Python dictionary into a JSON string using `ujson.dumps()` and then decode a JSON string back into a Python dictionary using `ujson.loads()`.
Ensure that any custom `toDict()` implementation always returns a dictionary, or handle the `TypeError` appropriately.
Update parsers or consumers of ujson output to expect lowercase boolean strings for dictionary keys.
Update error handling blocks to catch `JSONDecodeError` (or its base class `ValueError`) instead of `SystemError` for JSON parsing failures.
Upgrade to Python 3.10 or newer. For projects requiring Python 3.9, pin ujson to `<5.12.0`.
Upgrade to Python 3.9 or newer, or PyPy3.11 or newer. For projects requiring these EOL versions, pin ujson to `<5.11.0`.
Evaluate migrating to `orjson` for new projects or existing projects where security is a paramount concern.
Ensure you are using the latest stable version of ujson (5.12.0 or newer) to benefit from security and stability fixes.