Skip to main content

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

Project description

json5kit

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

Currently a work in progress

Currently supports parsing all of JSON syntax, and converting it back to source. Also supports single line // comments.

Installation

pip install json5kit

Usage

This is not the intended way to use the library. The correct way to modify a tree would be to use visitors, which will be added soon.

>>> 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
}

>>> tree.value.data[0][1].members[2] = json5kit.Json5Number('3', 3, [])
>>> print(tree.to_source())

{
  "items": [1, 2, 3],  // change this to 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 .
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json5kit-0.2.1.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distribution

json5kit-0.2.1-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page