Skip to main content

json5kit

A Roundtrip parser and CST for JSON, JSONC and JSON5.

JSON5 is a superset of JSON, that allows trailing commas, comments, unquoted and single-quoted object keys, and a lot more.

Currently supports parsing most JSON5 syntax, and converting it back to source. Also supports single line // comments.

Installation

pip install json5kit

Usage

>>> source = """
... {
...   items: [1, 2, 4],  // change this to 3
... }
... """
>>> import json5kit
>>> tree = json5kit.parse(source)
>>> print(tree.to_source())

{
  items: [1, 2, 4],  // change this to 3
}

>>> print(tree.to_json())
{"items":[1,2,4]}

>>> # Let's replace the `4` with `3` now:
>>> class ReplaceFourWithThree(json5kit.Json5Transformer):
...     def visit_Number(self, node):
...         if node.value == 4:
...             return node.replace(value=3)
...         return node
...
>>> ReplaceFourWithThree().visit(tree)
>>> print(tree.to_source())

{
  items: [1, 2, 3],  // change this to 3
}
>>> print(tree.to_json())
{"items":[1,2,3]}

Development / Testing

  • Clone the project:

    git clone https://github.com/tusharsadhwani/json5kit
    cd json5kit
    
  • Setup a virtual environment:

    virtualenv venv
    . venv/bin/activate
    
  • Do an editable install of the project, that way you don't have to keep reinstalling:

    pip install -r requirements-dev.txt
    
  • Run tests:

    pytest
    
  • Run type checking:

    mypy .
    

Metadata

Release files for json5kit 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json5kit 0.4.0
File Size Uploaded
json5kit-0.4.0.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for json5kit 0.4.0
File Interpreter ABI Platform
json5kit-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.6 kB

Release files / json5kit-0.4.0.tar.gz

Download URL json5kit-0.4.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0f7978bed6aa539133873bda602aa3f130ee83cfdafa93565b55a63a5d2f3490
BLAKE2b-256 checksum
How to use checksums
13678d48f04daae6a794f4b847f44a8368cd48597da778edc4efca35305b61c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / json5kit-0.4.0-py3-none-any.whl

Download URL json5kit-0.4.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8fac2788abd070bdffbfad9bc0c7755bb7c259fa56a163b8517ba5aa4d0e2cb7
BLAKE2b-256 checksum
How to use checksums
1b7272cf4310a3d6cab45d48cb27e5f5e8420e1b955bb5cb0ab6e5f8adfa2e8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page