Typing Stubs for simplejson

3.20.0.20260408 · active · verified Thu Apr 09

types-simplejson is a stub package providing static type-checking annotations for the 'simplejson' library. It enables type checkers like MyPy and Pyright to analyze code that uses simplejson for JSON serialization and deserialization. This package is part of the broader typeshed project and currently aims to provide accurate annotations for simplejson version 3.20.*.

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of `simplejson` with type hints provided by `types-simplejson`. The code serializes a dictionary to a JSON string and then deserializes it back to a dictionary, with type annotations for clarity and static analysis.

import simplejson
from typing import Any, Dict, Union

def serialize_and_deserialize(data: Dict[str, Union[str, int, bool]]) -> Dict[str, Any]:
    """
    Serializes a dictionary to a JSON string and then deserializes it.
    """
    json_string: str = simplejson.dumps(data, indent=2, sort_keys=True)
    print(f"Serialized JSON:\n{json_string}")
    deserialized_data: Dict[str, Any] = simplejson.loads(json_string)
    print(f"Deserialized data: {deserialized_data}")
    return deserialized_data

if __name__ == "__main__":
    my_data = {"name": "Alice", "age": 30, "is_student": False}
    result = serialize_and_deserialize(my_data)
    assert result == my_data

view raw JSON →