ujson: Ultra Fast JSON for Python

5.12.0 · maintenance · verified Sun Mar 29

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.

Warnings

Install

Imports

Quickstart

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()`.

import ujson

data = {
    "name": "Alice",
    "age": 30,
    "is_student": False,
    "courses": ["Math", "Science"],
    "address": None
}

# Encode Python dict to JSON string
json_string = ujson.dumps(data, indent=4) # indent for pretty-printing
print("Encoded JSON:", json_string)

# Decode JSON string to Python dict
decoded_data = ujson.loads(json_string)
print("Decoded data:", decoded_data)
print("Type of decoded_data:", type(decoded_data))

view raw JSON →