A Python implementation of the JSON5 data format.
Actively maintained. Last release 7 weeks ago, commits in 10 of the last 26 weeks. A safe choice.
pip install json5pyjson5
A Python implementation of the JSON5 data format.
JSON5 extends the JSON data interchange format to make it slightly more usable as a configuration language:
-
JavaScript-style comments (both single and multi-line) are legal.
-
Object keys may be unquoted if they are legal ECMAScript identifiers
-
Objects and arrays may end with trailing commas.
-
Strings can be single-quoted, and multi-line string literals are allowed.
There are a few other more minor extensions to JSON; see the above page for the full details.
This project implements a reader and writer implementation for Python; where possible, it mirrors the standard Python JSON API package for ease of use.
There is one notable difference from the JSON api: the load() and
loads() methods support optionally checking for (and rejecting) duplicate
object keys; pass allow_duplicate_keys=False to do so (duplicates are
allowed by default).
This is an early release. It has been reasonably well-tested, but it is SLOW. It can be 1000-6000x slower than the C-optimized JSON module, and is 200x slower (or more) than the pure Python JSON module.
Please Note: This library only handles JSON5 documents, it does not allow you to read arbitrary JavaScript. For example, bare integers can be legal object keys in JavaScript, but they aren't in JSON5.
One more note: It's long past time to declare this a 1.0 stable
product and move on, so I am preparing to do so. If the latest version
proves to be stable (e.g., no bug reports for a month or so), I plan to
switch the directory layout to move json5 under a src directory
(i.e., use a src-layout to avoid accidentally importing an unpackaged
version of the code), bake that for a month or so as well, and then
release this as 1.0.
Known issues
-
Did I mention that it is SLOW?
-
The implementation is based on recursive descent parsing and relies on the runtime stack for recursion; this means that really deeply nested data might trigger a
RecursionError, but this doesn't seem to be a problem in normal practice. If it is, please report it and I can raise the priority of fixing this properly :).