{"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":"python","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,"search_vec":"'5.10.0.20250822':32 '5.11.0':45 'analyz':23 'annot':52 'checker':17 'code':24 'current':29 'develop':65 'enabl':15 'environ':66 'includ':48 'json':69 'librari':14 'like':18 'make':53 'mypi':19 'newer':47 'note':41 'older':60 'packag':6 'perform':70 'primarili':57 'project':40 'provid':7 'pyright':21 'relev':58 'sourc':36 'specif':64 'static':8 'stub':2,10,34,68 'type':1,9,16,51,55,67 'types-ujson':54 'typesh':39 'ujson':4,13,27,43,56,61 'use':26 'version':30,44,62","created_at":"2026-04-11T01:44:44.845081+00:00","updated_at":"2026-04-16T23:47:34.124594+00:00","problems":{"verify_error":"error: Failed to parse: `ujson types-ujson`\n  Caused by: Expected one of `@`, `(`, `<`, `=`, `>`, `~`, `!`, `;`, found `t`\nujson types-ujson\n      ^"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"5.10.0.20250822","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/typeshed-internal/stub_uploader","docs":null,"changelog":"https://github.com/typeshed-internal/stub_uploader/blob/main/data/changelogs/ujson.md","pypi":"https://pypi.org/project/types-ujson/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["type-stubs","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-05","install_tag":null}}