# json5kit
A Roundtrip parser and CST for JSON, JSONC and JSON5.
[JSON5](https://json5.org) 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
```bash
pip install json5kit
```
## Usage
```python
>>> 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:
```bash
git clone https://github.com/tusharsadhwani/json5kit
cd json5kit
```
- Setup a virtual environment:
```bash
virtualenv venv
. venv/bin/activate
```
- Do an editable install of the project, that way you don't have to keep
reinstalling:
```bash
pip install -r requirements-dev.txt
```
- Run tests:
```bash
pytest
```
- Run type checking:
```bash
mypy .
```
Raw data
{
"_id": null,
"home_page": "https://github.com/tusharsadhwani/json5kit",
"name": "json5kit",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Tushar Sadhwani",
"author_email": "tushar.sadhwani000@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/13/67/8d48f04daae6a794f4b847f44a8368cd48597da778edc4efca35305b61c0/json5kit-0.4.0.tar.gz",
"platform": null,
"description": "# json5kit\n\nA Roundtrip parser and CST for JSON, JSONC and JSON5.\n\n[JSON5](https://json5.org) is a superset of JSON, that allows trailing commas,\ncomments, unquoted and single-quoted object keys, and a lot more.\n\nCurrently supports parsing most JSON5 syntax, and converting it back to source.\nAlso supports single line `// comments`.\n\n## Installation\n\n```bash\npip install json5kit\n```\n\n## Usage\n\n```python\n>>> source = \"\"\"\n... {\n... items: [1, 2, 4], // change this to 3\n... }\n... \"\"\"\n>>> import json5kit\n>>> tree = json5kit.parse(source)\n>>> print(tree.to_source())\n\n{\n items: [1, 2, 4], // change this to 3\n}\n\n>>> print(tree.to_json())\n{\"items\":[1,2,4]}\n\n>>> # Let's replace the `4` with `3` now:\n>>> class ReplaceFourWithThree(json5kit.Json5Transformer):\n... def visit_Number(self, node):\n... if node.value == 4:\n... return node.replace(value=3)\n... return node\n...\n>>> ReplaceFourWithThree().visit(tree)\n>>> print(tree.to_source())\n\n{\n items: [1, 2, 3], // change this to 3\n}\n>>> print(tree.to_json())\n{\"items\":[1,2,3]}\n```\n\n## Development / Testing\n\n- Clone the project:\n\n ```bash\n git clone https://github.com/tusharsadhwani/json5kit\n cd json5kit\n ```\n\n- Setup a virtual environment:\n\n ```bash\n virtualenv venv\n . venv/bin/activate\n ```\n\n- Do an editable install of the project, that way you don't have to keep\n reinstalling:\n\n ```bash\n pip install -r requirements-dev.txt\n ```\n\n- Run tests:\n\n ```bash\n pytest\n ```\n\n- Run type checking:\n\n ```bash\n mypy .\n ```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Roundtrip parser and CST for JSON, JSONC and JSON5.",
"version": "0.4.0",
"project_urls": {
"Homepage": "https://github.com/tusharsadhwani/json5kit"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1b7272cf4310a3d6cab45d48cb27e5f5e8420e1b955bb5cb0ab6e5f8adfa2e8d",
"md5": "1010e8287321d15111ee85d6f23f5811",
"sha256": "8fac2788abd070bdffbfad9bc0c7755bb7c259fa56a163b8517ba5aa4d0e2cb7"
},
"downloads": -1,
"filename": "json5kit-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1010e8287321d15111ee85d6f23f5811",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 8730,
"upload_time": "2023-05-16T20:48:20",
"upload_time_iso_8601": "2023-05-16T20:48:20.654323Z",
"url": "https://files.pythonhosted.org/packages/1b/72/72cf4310a3d6cab45d48cb27e5f5e8420e1b955bb5cb0ab6e5f8adfa2e8d/json5kit-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "13678d48f04daae6a794f4b847f44a8368cd48597da778edc4efca35305b61c0",
"md5": "90e211b71951a8c9801ce90e53b4917d",
"sha256": "0f7978bed6aa539133873bda602aa3f130ee83cfdafa93565b55a63a5d2f3490"
},
"downloads": -1,
"filename": "json5kit-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "90e211b71951a8c9801ce90e53b4917d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 8866,
"upload_time": "2023-05-16T20:48:22",
"upload_time_iso_8601": "2023-05-16T20:48:22.867318Z",
"url": "https://files.pythonhosted.org/packages/13/67/8d48f04daae6a794f4b847f44a8368cd48597da778edc4efca35305b61c0/json5kit-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-16 20:48:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tusharsadhwani",
"github_project": "json5kit",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"tox": true,
"lcname": "json5kit"
}