{"id":1887,"library":"types-simplejson","title":"Typing Stubs for simplejson","description":"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.*.","status":"active","version":"3.20.0.20260408","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","json","type-checking","typeshed"],"install":[{"cmd":"pip install types-simplejson","lang":"bash","label":"Install types-simplejson"},{"cmd":"pip install simplejson","lang":"bash","label":"Install runtime dependency"}],"dependencies":[{"reason":"This package provides only type-checking stubs. The 'simplejson' library must be installed separately for runtime functionality.","package":"simplejson","optional":false}],"imports":[{"note":"This package provides static type-checking annotations for the `simplejson` library. You should import `simplejson` directly for runtime usage and type hints will be automatically picked up.","wrong":"import types_simplejson","symbol":"simplejson","correct":"import simplejson"},{"symbol":"JSONDecodeError","correct":"from simplejson import JSONDecodeError"}],"quickstart":{"code":"import simplejson\nfrom typing import Any, Dict, Union\n\ndef serialize_and_deserialize(data: Dict[str, Union[str, int, bool]]) -> Dict[str, Any]:\n    \"\"\"\n    Serializes a dictionary to a JSON string and then deserializes it.\n    \"\"\"\n    json_string: str = simplejson.dumps(data, indent=2, sort_keys=True)\n    print(f\"Serialized JSON:\\n{json_string}\")\n    deserialized_data: Dict[str, Any] = simplejson.loads(json_string)\n    print(f\"Deserialized data: {deserialized_data}\")\n    return deserialized_data\n\nif __name__ == \"__main__\":\n    my_data = {\"name\": \"Alice\", \"age\": 30, \"is_student\": False}\n    result = serialize_and_deserialize(my_data)\n    assert result == my_data","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `simplejson` is installed in your environment alongside `types-simplejson`: `pip install simplejson`.","message":"The `types-simplejson` package provides *only* type-checking stubs. For actual runtime functionality, you *must* also install the `simplejson` library separately.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `import simplejson` (or `from simplejson import ...`) in your code. `types-simplejson` provides the type hints behind the scenes to your type checker.","message":"Do not attempt to import directly from `types_simplejson`. The imports for your code should always reference the `simplejson` library itself.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Align your `simplejson` installation to match the version range specified by the `types-simplejson` metadata (e.g., `pip install 'simplejson>=3.20,<3.21'`).","message":"Version compatibility between `types-simplejson` and the runtime `simplejson` library is crucial for accurate type checking. This stub package aims to provide accurate annotations for `simplejson==3.20.*`.","severity":"gotcha","affected_versions":"All versions of types-simplejson with corresponding simplejson versions"},{"fix":"If your application relies on serializing or deserializing `NaN`, `Infinity`, or `-Infinity` values, you must explicitly set `allow_nan=True` in your `simplejson.dumps()` or `simplejson.dump()` calls.","message":"The `simplejson` library (version 3.19.1) introduced a breaking change by setting the default value of the `allow_nan` parameter in `dumps` and `dump` to `False`.","severity":"breaking","affected_versions":"simplejson >= 3.19.1"},{"fix":"Ensure your project's Python interpreter is within the supported range (Python 3.10-3.14) to guarantee proper type-checking behavior and avoid unexpected errors.","message":"Typeshed stubs, including `types-simplejson`, are built and tested against specific Python versions. This package requires Python >=3.10 and is validated against Python versions 3.10 to 3.14.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}