Typing Stubs for ujson

5.10.0.20250822 · maintenance · verified Fri Apr 10

This package provides static typing stubs for the `ujson` library, enabling type checkers like MyPy and Pyright to analyze code that uses `ujson`. The current version is 5.10.0.20250822. These stubs are sourced from the typeshed project. Note that `ujson` versions 5.11.0 and newer include their own type annotations, making `types-ujson` primarily relevant for older `ujson` versions or specific development environments.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic usage of `ujson.dumps` and `ujson.loads` with type hints, leveraging the `types-ujson` stubs for static analysis.

import ujson
from typing import Dict, Any, List

data: Dict[str, Any] = {
    "name": "Alice",
    "age": 30,
    "isStudent": False,
    "courses": ["History", "Math"]
}

# Encode Python dict to JSON string with type hinting
json_string: str = ujson.dumps(data)
print(f"Encoded JSON: {json_string}")

# Decode JSON string to Python dict with type hinting
decoded_data: Dict[str, Any] = ujson.loads(json_string)
print(f"Decoded data: {decoded_data}")

# Accessing a value from decoded data
name: str = decoded_data['name']
print(f"Name: {name}")

view raw JSON →