{"id":2834,"library":"types-ujson","title":"Typing Stubs for ujson","description":"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.","status":"maintenance","version":"5.10.0.20250822","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","json","performance"],"install":[{"cmd":"pip install ujson types-ujson","lang":"bash","label":"Install `ujson` and its typing stubs"}],"dependencies":[{"reason":"This package provides type stubs for `ujson`; the `ujson` library itself is required for runtime functionality.","package":"ujson","optional":false}],"imports":[{"symbol":"ujson","correct":"import ujson"},{"symbol":"dumps","correct":"from ujson import dumps"},{"symbol":"loads","correct":"from ujson import loads"}],"quickstart":{"code":"import ujson\nfrom typing import Dict, Any, List\n\ndata: Dict[str, Any] = {\n    \"name\": \"Alice\",\n    \"age\": 30,\n    \"isStudent\": False,\n    \"courses\": [\"History\", \"Math\"]\n}\n\n# Encode Python dict to JSON string with type hinting\njson_string: str = ujson.dumps(data)\nprint(f\"Encoded JSON: {json_string}\")\n\n# Decode JSON string to Python dict with type hinting\ndecoded_data: Dict[str, Any] = ujson.loads(json_string)\nprint(f\"Decoded data: {decoded_data}\")\n\n# Accessing a value from decoded data\nname: str = decoded_data['name']\nprint(f\"Name: {name}\")","lang":"python","description":"This quickstart demonstrates basic usage of `ujson.dumps` and `ujson.loads` with type hints, leveraging the `types-ujson` stubs for static analysis."},"warnings":[{"fix":"Evaluate migrating from `ujson` to `orjson` or the standard `json` library, especially for new projects or performance-critical applications.","message":"The underlying `ujson` library is in maintenance-only mode due to architectural limitations and potential security vulnerabilities, with active development paused. Users are encouraged to consider `orjson` as a faster and more secure alternative.","severity":"deprecated","affected_versions":"All versions of `ujson` (and by extension `types-ujson`)"},{"fix":"If using `ujson` 5.11.0 or newer, uninstall `types-ujson` (`pip uninstall types-ujson`). Rely on the type annotations provided directly by the `ujson` package.","message":"For `ujson` versions 5.11.0 and newer, the `ujson` package itself includes type annotations. Installing `types-ujson` alongside these versions is redundant and may lead to conflicts or incorrect type checking behavior.","severity":"breaking","affected_versions":"ujson>=5.11.0"},{"fix":"Ensure both `ujson` and `types-ujson` are installed via `pip install ujson types-ujson`.","message":"`types-ujson` only provides type hints; the actual `ujson` library must be installed for runtime execution. Failing to install `ujson` will result in `ModuleNotFoundError` at runtime.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If exact floating-point precision is critical, consider using Python's standard `json` module or ensure thorough testing of `ujson`'s output for your specific data.","message":"`ujson.dumps()` has known issues with floating-point precision, which can lead to slight discrepancies compared to the standard library's `json.dumps()`, even when `double_precision` is explicitly set.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `ujson` is updated to at least version `5.12.0` to address known vulnerabilities and memory-related bugs. Optimize code to avoid repeated encoding of large, mutable objects in performance-critical loops if memory consumption becomes an issue.","message":"`ujson` has experienced memory leak issues, particularly in `ujson.dumps()` when repeatedly encoding large objects or dictionaries with non-string keys within a loop.","severity":"gotcha","affected_versions":"Prior to ujson 5.2.0 (and potentially others)"},{"fix":"Upgrade `ujson` to version 5.12.0 or higher to mitigate these known security risks.","message":"Several security vulnerabilities have been identified in `ujson`, including integer overflows with the `indent` parameter and improper handling of syntactically invalid JSON structures.","severity":"gotcha","affected_versions":"ujson < 5.12.0"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}