{"id":21484,"library":"json-five","title":"json-five","description":"A JSON5 parser and serializer for Python that supports round-trip preservation of comments, identifiers, and formatting. Current version 1.1.2, with a release cadence of a few months. Requires Python >=3.8.","status":"active","version":"1.1.2","language":"python","source_language":"en","source_url":"https://github.com/spyoungtech/json-five","tags":["json5","comments","round-trip","parser","serialization"],"install":[{"cmd":"pip install json-five","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Parser implementation dependency, with compatibility fixed in v0.8.0","package":"sly","optional":false}],"imports":[{"note":"Main class for encoding/decoding with round-trip preservation","symbol":"JSON5Codec","correct":"from json_five.codec import JSON5Codec"},{"note":"Base class for the comment-preserving model","symbol":"Node","correct":"from json_five.model import Node"},{"note":"In v1.0.0+, the top-level imports are the canonical API; codec submodule also available.","wrong":"from json_five.codec import loads","symbol":"loads","correct":"from json_five import loads"},{"note":"Same as loads – top-level import is preferred.","wrong":"from json_five.codec import dumps","symbol":"dumps","correct":"from json_five import dumps"}],"quickstart":{"code":"from json_five import loads, dumps\n\n# Parse JSON5 string (supports comments, trailing commas, etc.)\ndata = '''{\n  \"name\": \"Alice\",\n  // This is a comment\n  \"age\": 30,\n}'''\nparsed = loads(data)\nprint(parsed)  # {'name': 'Alice', 'age': 30}\n\n# Round-trip with comments preserved (using codec)\nfrom json_five.codec import JSON5Codec\ncodec = JSON5Codec()\nobj = codec.decode(data)\nprint(codec.encode(obj)) # includes comments\n\n# Dump without indentation (default)\nprint(dumps(parsed))  # {\"name\":\"Alice\",\"age\":30}\n\n# Dump with indentation\nprint(dumps(parsed, indent=2))","lang":"python","description":"Basic usage: parse JSON5 string, round-trip with comments, and dump with indentation."},"warnings":[{"fix":"Upgrade Python to 3.8 or later.","message":"In v1.0.0, support for Python 3.6 and 3.7 was dropped. Python >=3.8 is required.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use `json_five.codec.JSON5Codec` for round-trip comment preservation.","message":"The `loads` and `dumps` functions return plain Python objects by default, not the comment-preserving model. To preserve comments, use `JSON5Codec.decode/encode`.","severity":"gotcha","affected_versions":"all"},{"fix":"If you rely on `isinstance(x, str)` checks, note that `JsonIdentifier` now passes. To disable parsing of identifiers, pass `parse_json5_identifiers=False`.","message":"JSON5 identifiers (e.g. unquoted keys like `{foo: 1}`) are parsed as `JsonIdentifier` objects, which inherit from `str` since v1.0.0. Before v1.0.0, they were `UserString` subclasses, which could break code that expects `str`-only behavior.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `from json_five import loads, dumps` instead of `from json_five.codec import loads, dumps`.","message":"The `codec` module's `loads` and `dumps` are still available but importing them from `json_five` is the recommended API.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use `import json_five` or `from json_five import ...`.","cause":"Incorrect import path – the package name on PyPI is 'json-five', but the module is 'json_five'.","error":"ModuleNotFoundError: No module named 'json_five'"},{"fix":"Ensure the input is valid JSON5 (use linters or test with a simple object).","cause":"Passing a bogus string that is not valid JSON5 (e.g., single-line comment syntax without proper structure).","error":"json_five.exceptions.JSON5DecodeError: ..."},{"fix":"Use `from json_five.codec import JSON5Codec`.","cause":"Trying to import JSON5Codec directly from top-level module; it is in the codec submodule.","error":"AttributeError: module 'json_five' has no attribute 'JSON5Codec'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}