{"id":2695,"library":"pyjson5","title":"pyjson5","description":"PyJSON5 is a high-performance JSON5 serializer and parser library for Python 3, implemented in Cython. It extends the standard JSON format with features like comments, unquoted keys, and trailing commas, making it ideal for human-editable configuration files. This library is actively maintained, with frequent updates and a current stable version of 2.0.0.","status":"active","version":"2.0.0","language":"python","source_language":"en","source_url":"https://github.com/Kijewski/pyjson5","tags":["json","json5","parser","serializer","cython","configuration"],"install":[{"cmd":"pip install pyjson5","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The PyPI package `json5` is a different, pure-Python implementation. This library (pyjson5, the Cython one) exposes its functions directly under the `pyjson5` module. Using `import json5` will import the other library if installed.","wrong":"import json5","symbol":"loads, dumps, load, dump","correct":"import pyjson5\n# Use pyjson5.loads, pyjson5.dumps, etc."}],"quickstart":{"code":"import pyjson5\nimport io\n\njson5_data = \"\"\"\n{\n  // This is a comment\n  name: 'Project Alpha',\n  version: 1.0.0,\n  features: [\n    'comments',\n    'trailing commas',\n  ],\n  config: { key: 'value', }, // Trailing comma\n}\n\"\"\"\n\n# Load from a string\ndata = pyjson5.loads(json5_data)\nprint(f\"Loaded data: {data}\")\n\n# Dump to a string\noutput_json5 = pyjson5.dumps(data, indent=2)\nprint(f\"\\nDumped JSON5:\\n{output_json5}\")\n\n# Load from a file-like object (StringIO acts like a file)\nfile_like_obj_read = io.StringIO(json5_data)\nfile_data = pyjson5.load(file_like_obj_read)\nprint(f\"\\nLoaded from file-like object: {file_data}\")\n\n# Dump to a file-like object\nfile_like_obj_write = io.StringIO()\npyjson5.dump(data, file_like_obj_write, indent=2)\nprint(f\"\\nDumped to file-like object:\\n{file_like_obj_write.getvalue()}\")\n","lang":"python","description":"This quickstart demonstrates how to load JSON5 data from a string using `pyjson5.loads` and dump Python objects back to a JSON5 string using `pyjson5.dumps`. It also shows reading from and writing to file-like objects using `pyjson5.load` and `pyjson5.dump` respectively. Note the use of `io.StringIO` for in-memory file operations."},"warnings":[{"fix":"Ensure that file-like objects passed to `pyjson5.dump()` are opened in text write mode (e.g., `open('file.json5', 'w')`) rather than binary write mode (`'wb'`).","message":"In `pyjson5` v2.0.0, the `dump()` function now consistently writes `str` (Unicode) instead of `bytes` to file-like objects. This is a change from previous versions and can lead to `TypeError: a bytes-like object is required, not 'str'` if the target file object is opened in binary write mode (`'wb'`).","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade your Python environment to version 3.8 or newer to use `pyjson5` v2.0.0 and subsequent releases. If backward compatibility with older Python versions is required, use `pyjson5` v1.x.","message":"Starting with `pyjson5` v2.0.0, the library explicitly requires Python 3.8 or later. Versions prior to `v1.6.8` supported Python 3.5+, and `v1.6.8` raised the minimum to Python 3.7+.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Instead of `cls`, use the `default` keyword argument in `dumps` or `dump` for custom serialization of unsupported types. For custom deserialization, manual post-processing of the loaded Python object is often required.","message":"Unlike Python's standard `json` module, `pyjson5` does not support the `cls` keyword argument for custom `JSONDecoder` or `JSONEncoder` subclasses in its `load`, `loads`, `dump`, or `dumps` functions. This is due to its Cython-based parsing and serialization approach.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consider the use case: if machine-to-machine interoperability is paramount, use Python's built-in `json` module. If human readability and maintainability of configuration files are the priority, `pyjson5` is a suitable choice.","message":"JSON5 is designed for human-editable configuration files, allowing features like comments and unquoted keys. It is generally not recommended for strict machine-to-machine communication, where the more rigid standard JSON format is often preferred due to broader tooling support and stricter validation.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To enforce strict parsing and disallow duplicate keys, pass `allow_duplicate_keys=False` to the `load()` or `loads()` functions. For example: `pyjson5.loads(json5_string, allow_duplicate_keys=False)`.","message":"By default, `pyjson5.load()` and `pyjson5.loads()` allow duplicate keys within an object (dictionary) in the JSON5 input. When duplicate keys are present, the last encountered value for that key will override previous ones.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'2.0.0':57 '3':15 'activ':46 'comma':33 'comment':28 'configur':41,63 'current':53 'cython':18,62 'edit':40 'extend':20 'featur':26 'file':42 'format':24 'frequent':49 'high':6 'high-perform':5 'human':39 'human-edit':38 'ideal':36 'implement':16 'json':23,58 'json5':8,59 'key':30 'librari':12,44 'like':27 'maintain':47 'make':34 'parser':11,60 'perform':7 'pyjson5':1,2 'python':14 'serial':9,61 'stabl':54 'standard':22 'trail':32 'unquot':29 'updat':50 'version':55","created_at":"2026-04-11T01:38:55.207749+00:00","updated_at":"2026-04-16T18:30:30.513816+00:00","problems":[{"fix":"Install the library using pip: `pip install pyjson5`","cause":"The 'pyjson5' library is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'pyjson5'"},{"fix":"Carefully review the JSON5 input for syntax errors, ensuring correct object/array delimiters, proper key quoting, and valid characters. Use a JSON5 linter or validator to pinpoint the exact location of the error.","cause":"The input string or file provided to `pyjson5.decode()` or `pyjson5.loads()` contains invalid JSON5 syntax, such as an unexpected character, missing comma, or unquoted key that isn't a valid ECMAScript identifier.","error":"pyjson5.Json5IllegalCharacter: An unexpected character was encountered"},{"fix":"Check the `pyjson5` function's documentation to understand the expected types for its arguments and ensure your data matches those requirements. For encoding complex types, provide a `default` function to handle custom serialization.","cause":"A function in `pyjson5` was called with an argument of an incorrect or unsupported Python type, such as attempting to encode an unstringifiable object without a custom default handler, or providing non-string data to a decoding function that expects a string.","error":"TypeError: An argument had a wrong type"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.0.1","cli_name":"json5","cli_version":"sh: 1: json5: not found","type":"library","homepage":null,"github":"https://github.com/Kijewski/pyjson5","docs":"https://pyjson5.readthedocs.io/","changelog":"https://github.com/Kijewski/pyjson5/blob/main/CHANGELOG.md","pypi":"https://pypi.org/project/pyjson5/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["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-28","install_tag":null}}