Parsing for extended JSON with optional comments and trailing commas
Project description
JSONXOX: Extended JSON Parsing
Do you love the JSON serialization format but wish it included support for optional comments and trailing commas? Well if so, the JSONXOX library is for you.
The JSONXOX library provides support for parsing extended JSON files and strings – JSON files and strings which may contain optional C-style single-line and multi-line comments as well as trailing commas.
Requirements
The JSONXOX library has been tested with Python 3.10, 3.11, 3.12, 3.13 and 3.14. The library has not been tested with, nor is it likely compatible with Python 3.9 and earlier.
Installation
The JSONXOX library is available from PyPI, so may be added to a project's dependencies
via its requirements.txt file or similar by referencing the JSONXOX library's name,
jsonxox, or the library may be installed directly into the local runtime environment
using pip install by running the following command:
$ pip install jsonxox
Usage Example
To use the JSONXOX library, simply import the library into your project as a drop-in
replacement for the standard json library, and use it as you would to load a JSON file
or JSON string. The library can be used to load standard JSON files and strings as well
as extended JSON files and strings containing single- and multi-line comments as well as
trailing commas. The library can also be used to save standard JSON files and strings.
See the Methods section for more information about the methods provided by the library.
import jsonxox
sample: str = """
/* this is a multi-line comment block
that can span multiple lines or just a single line
*/
{
"a": 123, /* this is also a multi-line comment block (using a single line) */
// this is a single-line comment
"b": "456", // notice the trailing comma
}
"""
data = jsonxox.loads(sample)
assert isinstance(data, dict)
assert "a" in data
assert data["a"] == 123
assert "b" in data
assert data["b"] == "456"
Methods
The jsonxox library provides the following methods, mirroring the standard json
library in its available methods and overall functionality:
-
load(handle, **kwargs)(object) – Theload()method takes a file handle or file handle like object that is an instance ofio.TextIOWrapperor one of its subclasses as input and removes any single and multi-line comments as well as any trailing commas from the input string contents read from the file handle, and then passes the cleaned string to the standard library'sjson.loads()method for quick deserialization to its corresponding Python data types. Any additional keyword arguments are passed to thejson.loads()method, as such any additional keyword arguments must be compatible with thejson.loads()method. -
loads(handle, **kwargs)(object) – Theloads()method takes a string as input and removes any single and multi-line comments as well as any trailing commas from the input string, and then passes the cleaned string to the standard library'sjson.loads()method for quick deserialization to its corresponding Python data types. Any additional keyword arguments are passed to thejson.loads()method, as such any additional keyword arguments must be compatible with thejson.loads()method -
dump(*args, **kwargs)– Thedump()method is a passthrough to the standardjsonlibrary'sdump()method and accepts the same arguments and has the same return values. Note that thedump()method cannot be used to re-save any comments or trailing commas that may have been present in the original extended JSON file or string. -
dumps(*args, **kwargs)(str) – Thedumps()method is a passthrough to the standardjsonlibrary'sdumps()method and accepts the same arguments and has the same return values. Note that thedumps()method cannot be used to re-save any comments or trailing commas that may have been present in the original extended JSON file or string.
Classes
The jsonxox library provides the following classes, mirroring the standard json
library in its available classes:
-
JSONDecoder– TheJSONDecoderclass is a direct import of and reference to the standardjsonlibrary'sJSONDecoderclass. -
JSONEncoder– TheJSONEncoderclass is a direct import of and reference to the standardjsonlibrary'sJSONEncoderclass.
Exceptions
The jsonxox library provides the following exception classes, mirroring the standard
json library in its available exception classes:
-
JSONDecodeError– TheJSONDecodeErrorexception class is a direct import of and reference to the standardjsonlibrary'sJSONDecodeErrorexception class. -
JSONXOXDecodeError– TheJSONXOXDecodeErrorexception class is a subclass of the standardjsonlibrary'sJSONDecodeErrorclass and will be raised by thejsonxoxlibrary if an exception occurs while attempting to clean or load the JSON input.
Unit Tests
The JSONXOX library includes a suite of comprehensive unit tests which ensure that the
library functionality operates as expected. The unit tests were developed with and are
run via pytest.
To ensure that the unit tests are run within a predictable runtime environment where all
of the necessary dependencies are available, a Docker image is
created within which the tests are run. To run the unit tests, ensure Docker and Docker
Compose is installed, and perform the
following commands, which will build the Docker image via docker compose build and
then run the tests via docker compose run – the output the tests will be displayed:
$ docker compose build
$ docker compose run tests
To run the unit tests with optional command line arguments being passed to pytest,
append the relevant arguments to the docker compose run tests command, as follows, for
example passing -v to enable verbose output and -s to print standard output:
$ docker compose run tests -v -s
See the documentation for PyTest regarding available optional command line arguments.
Copyright & License Information
Copyright © 2023–2026 Daniel Sissman; licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jsonxox-0.8.0.tar.gz.
File metadata
- Download URL: jsonxox-0.8.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
583ed7d23267df560c452ccfe0227419bfffb220745f9f4d64503a9320db925c
|
|
| MD5 |
ea3a660f412091912de762160b455dfb
|
|
| BLAKE2b-256 |
bb8dd36efff95bb95bc3bdbe92d8795e735642acff2a78e82e2961ecc8d8d5e3
|
Provenance
The following attestation bundles were made for jsonxox-0.8.0.tar.gz:
Publisher:
python-publish.yml on bluebinary/jsonxox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jsonxox-0.8.0.tar.gz -
Subject digest:
583ed7d23267df560c452ccfe0227419bfffb220745f9f4d64503a9320db925c - Sigstore transparency entry: 942519980
- Sigstore integration time:
-
Permalink:
bluebinary/jsonxox@62a4d89e97baabf680fa8f1bace25f9554d4ca84 -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/bluebinary
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@62a4d89e97baabf680fa8f1bace25f9554d4ca84 -
Trigger Event:
release
-
Statement type:
File details
Details for the file jsonxox-0.8.0-py3-none-any.whl.
File metadata
- Download URL: jsonxox-0.8.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2cb361938509e239ae3bed2b9dfa54b82bcd92cab5c438652a6664c32fe92e2
|
|
| MD5 |
e32edd5f9eade06bd4ea74f225218071
|
|
| BLAKE2b-256 |
9790ced5437f827049e8443cb10b105e0ffde84a0445e5bc55544488f425ba4c
|
Provenance
The following attestation bundles were made for jsonxox-0.8.0-py3-none-any.whl:
Publisher:
python-publish.yml on bluebinary/jsonxox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jsonxox-0.8.0-py3-none-any.whl -
Subject digest:
d2cb361938509e239ae3bed2b9dfa54b82bcd92cab5c438652a6664c32fe92e2 - Sigstore transparency entry: 942519990
- Sigstore integration time:
-
Permalink:
bluebinary/jsonxox@62a4d89e97baabf680fa8f1bace25f9554d4ca84 -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/bluebinary
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@62a4d89e97baabf680fa8f1bace25f9554d4ca84 -
Trigger Event:
release
-
Statement type: