Registry / serialization / json-five

json-five

JSON →
library1.1.2pypypi✓ verified 80d ago

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.

pip install json-five
INSTALL
IMPORT
SIG · JSON-FIVE
J
json-five
serializationpythonv1.1.2
Install
2.2s avg
Import
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 20.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.2s · import 0.000s · 22MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

load
from json5 import load
from json_five.codec import JSON5Codec
loads
from json5 import loads
dump
from json5 import dump

Basic usage: parse JSON5 string, round-trip with comments, and dump with indentation.

from json_five import loads, dumps # Parse JSON5 string (supports comments, trailing commas, etc.) data = '''{ "name": "Alice", // This is a comment "age": 30, }''' parsed = loads(data) print(parsed) # {'name': 'Alice', 'age': 30} # Round-trip with comments preserved (using codec) from json_five.codec import JSON5Codec codec = JSON5Codec() obj = codec.decode(data) print(codec.encode(obj)) # includes comments # Dump without indentation (default) print(dumps(parsed)) # {"name":"Alice","age":30} # Dump with indentation print(dumps(parsed, indent=2))
Debug
Known issues
breakingIn v1.0.0, support for Python 3.6 and 3.7 was dropped. Python >=3.8 is required.
fix
Upgrade Python to 3.8 or later.
affects: >=1.0.0
gotchaThe `loads` and `dumps` functions return plain Python objects by default, not the comment-preserving model. To preserve comments, use `JSON5Codec.decode/encode`.
fix
Use `json_five.codec.JSON5Codec` for round-trip comment preservation.
affects: all
gotchaJSON5 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.
fix
If you rely on `isinstance(x, str)` checks, note that `JsonIdentifier` now passes. To disable parsing of identifiers, pass `parse_json5_identifiers=False`.
affects: >=1.0.0
deprecatedThe `codec` module's `loads` and `dumps` are still available but importing them from `json_five` is the recommended API.
fix
Use `from json_five import loads, dumps` instead of `from json_five.codec import loads, dumps`.
affects: >=1.0.0
Upgrade
Version history
1.1.2latest on PyPI · released Jun 11, 2024
Audit
Dependencies
slyrequiredParser implementation dependency, with compatibility fixed in v0.8.0
Agent activity
8 hits · last 30 days
node
8
Resources
json-five — pip install json-five · libregistry