{"id":2244,"library":"python-rapidjson","title":"Python RapidJSON","description":"Python-rapidjson is a Python 3 wrapper for the extremely fast C++ JSON parser and serialization library, RapidJSON. It provides high-performance JSON serialization and deserialization, including JSON Schema validation capabilities, while aiming for compatibility with the standard `json` module API. As of version 1.23, it maintains an active release cadence, frequently updating to support new Python versions and upstream RapidJSON improvements.","status":"active","version":"1.23","language":"en","source_language":"en","source_url":"https://github.com/python-rapidjson/python-rapidjson","tags":["json","rapidjson","parser","serialization","high-performance"],"install":[{"cmd":"pip install python-rapidjson","lang":"bash","label":"PyPI"},{"cmd":"conda install -c conda-forge python-rapidjson","lang":"bash","label":"Conda"}],"dependencies":[{"reason":"Core C++ library wrapped by python-rapidjson. Included as a submodule, but requires a C++ compiler if binary wheels are unavailable.","package":"RapidJSON","optional":false}],"imports":[{"symbol":"rapidjson","correct":"import rapidjson"},{"note":"While API-compatible, directly using `rapidjson.dumps` is intended. Be aware of minor incompatibilities with the standard `json` module's behavior.","wrong":"json.dumps(data)","symbol":"dumps","correct":"rapidjson.dumps(data)"},{"note":"While API-compatible, directly using `rapidjson.loads` is intended. Be aware of minor incompatibilities with the standard `json` module's behavior, especially regarding UTF-8 enforcement for bytes.","wrong":"json.loads(json_string)","symbol":"loads","correct":"rapidjson.loads(json_string)"},{"symbol":"Decoder","correct":"from rapidjson import Decoder, PM_COMMENTS, PM_TRAILING_COMMAS"},{"symbol":"Encoder","correct":"from rapidjson import Encoder"}],"quickstart":{"code":"import rapidjson\nimport os\n\n# Example data\ndata = {'name': 'Alice', 'age': 30, 'isStudent': False}\n\n# Serialize to JSON string\njson_string = rapidjson.dumps(data)\nprint(f\"Serialized: {json_string}\")\n\n# Deserialize from JSON string\nloaded_data = rapidjson.loads(json_string)\nprint(f\"Deserialized: {loaded_data}\")\n\n# Example with custom Decoder for relaxed syntax (JSONC, trailing commas)\ntry:\n    from rapidjson import Decoder, PM_COMMENTS, PM_TRAILING_COMMAS\n    decoder = Decoder(parse_mode=PM_COMMENTS | PM_TRAILING_COMMAS)\n    relaxed_json = '''\n    {\n        \"item\": \"value\", /* This is a comment */\n        \"count\": 123,   // Another comment\n        \"enabled\": true, // Trailing comma\n    }\n    '''\n    parsed_relaxed = decoder(relaxed_json)\n    print(f\"Parsed relaxed JSON: {parsed_relaxed}\")\nexcept ImportError:\n    print(\"Custom Decoder features not available (might be an older version or specific flags are missing).\")\n","lang":"python","description":"This quickstart demonstrates the basic serialization (`dumps`) and deserialization (`loads`) functionality of `python-rapidjson`, which mirrors the standard library `json` module. It also includes an example of using the `Decoder` class with `parse_mode` flags to handle more relaxed JSON syntax, such as comments and trailing commas."},"warnings":[{"fix":"Consult the `python-rapidjson` documentation for `Incompatibilities` and `Exposed functions and symbols` sections. Use specific `datetime_mode`, `number_mode`, `parse_mode`, `write_mode`, `iterable_mode`, and `mapping_mode` flags for fine-grained control.","message":"API Incompatibilities with standard `json` module: While `python-rapidjson` aims for `json` module compatibility, there are notable differences. `json.loads()` for bytes input only supports UTF-8. Dictionary key coercion (e.g., `True` to 'true') is not performed by default. The `indent` argument for pretty printing is supported, but specific `json` module behaviors like `None` for no indent or `sort_keys` as a direct argument have been superseded by `mapping_mode` options in v1.0+ (though old arguments are kept for backward compatibility).","severity":"gotcha","affected_versions":"All versions, v1.0+ for `mapping_mode` changes"},{"fix":"Ensure you have a C++ compiler installed, or install `python-rapidjson` via `conda` which typically manages compiler dependencies.","message":"C++ Compiler Requirement for Source Installation: If a pre-compiled binary wheel is not available for your specific Python version and operating system, `pip install` will attempt to compile `python-rapidjson` from source. This requires a C++ compiler toolchain (e.g., build-essential on Linux, Xcode Command Line Tools on macOS, or Visual C++ Build Tools on Windows) to be installed on your system.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Do not use `DM_UNIX_TIME` when calling `rapidjson.loads()` or initializing a `Decoder`. Select an appropriate `datetime_mode` that supports both serialization and deserialization if round-tripping datetime objects is required (e.g., `DM_ISO8601`).","message":"`DM_UNIX_TIME` for `dumps` (Serialization) Only: The `DM_UNIX_TIME` option, used with `datetime_mode` for serializing `date`, `datetime`, and `time` objects as numeric timestamps, is an irreversible operation. Consequently, it is only supported for `dumps()` (serialization) functions. Passing `DM_UNIX_TIME` to `loads()` (deserialization) will raise an error.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to version 1.15 or newer. For applications processing untrusted or extremely deep JSON, be aware of `sys.setrecursionlimit()` and how it affects parsing.","message":"Recursion Limit for Parsing: As of version 1.15, `python-rapidjson` honors the Python recursion limit during parsing to prevent potential denial-of-service attacks related to extremely deeply nested JSON structures. Prior versions may not have enforced this limit, making them potentially vulnerable to stack overflow issues with malicious inputs.","severity":"gotcha","affected_versions":"Versions < 1.15 (potential vulnerability), all versions (behavior change)"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}