Name | jsoncgx JSON |
Version |
1.1
JSON |
| download |
home_page | None |
Summary | An overpowered JSON-with-comments parser with inplace edition |
upload_time | 2024-05-11 17:44:25 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | None |
keywords |
json
jsonc
json with comments
json editor
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# jsoncgx: An overpowered JSON-with-comments parser with inplace edition
## Cool, a JSONC parser for Python. How do I load my file into a `dict`?
I'll stop you right here. If you're only looking at simply deserialising JSONC
files, this library is not for you.
`jsoncgx` is developped with 3 intentions:
1. Supporting C-style `//` and C++-style `/**/` comments. This part is typical,
there are lots of other libraries offering this functionality.
1. Offering more flexibility with the JSON syntax that your usual
straight-to-Python-types parser. Namely, the JSON format allows to have
multiple name:value pairs with the same name in the same object, but that is
not supported by Python's `dict`s.
1. Inplace edition, that is, being able to replace a chunk of a given JSONC file
without messing up its indentation or comments. Typically, libraries only
offer indentation _imitation_, that is, deserialisation makes guesses about
the indentation, and serialisation reproduces it.
## Installation
This library is [available on PyPI](https://pypi.org/project/jsoncgx/):
```
pip install --user jsoncgx
```
## Comparison / Quickstart / Demo
<table>
<tr>
<th></th>
<th>Standard Python module</th>
<th>
`jsoncgx`
</th>
</tr>
<tr>
<td>Loading JSON data</td>
<td>
```python
>>> import json
>>> data = json.loads('{ "answer": 42 }')
>>> data["answer"]
42
```
</td>
<td>
```python
>>> import jsoncgx
>>> editor = jsoncgx.loads('{ "answer": 42 }')
>>> editor.root["answer"][0]
42
```
</td>
</tr>
<tr>
<td>Editing JSON data</td>
<td>
```python
>>> data["answer"] = "spam"
>>> json.dumps(data)
'{"answer": "spam"}'
```
</td>
<td>
```python
>>> editor.root.editreplacevalue(0, "spam")
>>> editor.dumps()
'{ "answer": "spam" }'
```
</td>
</tr>
<tr>
<td>Working with JSON files</td>
<td>
```python
>>> with open("in.json") as f:
... data = json.load(f)
...
>>> with open("out.json", "w") as f:
... json.dump(data, f)
...
```
</td>
<td>
```python
>>> editor = json.loadf("in.json")
>>> editor.dumpf("out.json")
```
Or use `jsoncgx.load()` and `jsoncgx.JSONEditor.dump()` with a file handle, like the standard module.
</td>
</tr>
<tr>
<td>Non unique name</td>
<td>
```python
>>> data = json.loads(
... '{ "answer": 42, "answer": "spam" }')
>>> data["answer"]
'spam'
```
</td>
<td>
```python
>>> editor = jsoncgx.loads(
... '{ "answer": 42, "answer": "spam" }')
>>> editor.root["answer"][0]
42
>>> editor.root["answer"][1]
'spam'
```
</td>
</tr>
<tr>
<td>Comments</td>
<td>
```python
>>> data = json.loads(
... '{ "answer": /* eggs and */ 42 }')
Traceback (most recent call last):
...
json.decoder.JSONDecodeError: ...
```
</td>
<td>
```python
>>> editor = jsoncgx.loads(
... '{ "answer": /* eggs and */ 42 }')
>>> editor.root.editreplacevalue(0, "spam")
>>> editor.dumps()
'{ "answer": /* eggs and */ "spam" }'
```
</td>
</tr>
</table>
## What syntax does this parse exactly?
[ECMA-404](https://ecma-international.org/wp-content/uploads/ECMA-404_2nd_edition_december_2017.pdf)
with the following additional lexical elements:
* regex `//[^\n]*\n`, that is, the Unicode scalar sequence:
* U+002F,
* U+002F,
* any amount of any scalars except U+000A,
* U+000A.
* lazy regex `/\*.*\*/`, that is, the Unicode scalar sequence:
* U+002F,
* U+002A,
* any amount of any scalars except the sequence U+002A U+002F
* U+002A,
* U+002F.
Those elements are considered like whitespace.
## Architecture
![jsoncgx architecture](architecture.png)
## Changelog
### V1.1:
* `JSONNumber`, `JSONString`, `JSONBool`, and `JSONNull` have been replaced with
`JSONBuiltin`, for easier integration.
* `edit*()` methods that accepted `JSONValue` now also accept `int`, `float`,
`str`, `bool`, and `None`. They are automatically turned into `JSONBuiltin`.
Raw data
{
"_id": null,
"home_page": null,
"name": "jsoncgx",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "json, jsonc, json with comments, json editor",
"author": null,
"author_email": "cigix <cigix@cigix.me>",
"download_url": "https://files.pythonhosted.org/packages/9d/74/fd5c51ff08120e8ec8b55cf4ce57bef8774e04746524314308582f9046ab/jsoncgx-1.1.tar.gz",
"platform": null,
"description": "# jsoncgx: An overpowered JSON-with-comments parser with inplace edition\n\n## Cool, a JSONC parser for Python. How do I load my file into a `dict`?\n\nI'll stop you right here. If you're only looking at simply deserialising JSONC\nfiles, this library is not for you.\n\n`jsoncgx` is developped with 3 intentions:\n1. Supporting C-style `//` and C++-style `/**/` comments. This part is typical,\n there are lots of other libraries offering this functionality.\n1. Offering more flexibility with the JSON syntax that your usual\n straight-to-Python-types parser. Namely, the JSON format allows to have\n multiple name:value pairs with the same name in the same object, but that is\n not supported by Python's `dict`s.\n1. Inplace edition, that is, being able to replace a chunk of a given JSONC file\n without messing up its indentation or comments. Typically, libraries only\n offer indentation _imitation_, that is, deserialisation makes guesses about\n the indentation, and serialisation reproduces it.\n\n## Installation\n\nThis library is [available on PyPI](https://pypi.org/project/jsoncgx/):\n\n```\npip install --user jsoncgx\n```\n\n## Comparison / Quickstart / Demo\n\n<table>\n <tr>\n <th></th>\n <th>Standard Python module</th>\n<th>\n\n`jsoncgx`\n\n</th>\n </tr>\n <tr>\n <td>Loading JSON data</td>\n<td>\n\n```python\n>>> import json\n>>> data = json.loads('{ \"answer\": 42 }')\n>>> data[\"answer\"]\n42\n```\n\n</td>\n<td>\n\n```python\n\n>>> import jsoncgx\n>>> editor = jsoncgx.loads('{ \"answer\": 42 }')\n>>> editor.root[\"answer\"][0]\n42\n```\n\n</td>\n </tr>\n <tr>\n <td>Editing JSON data</td>\n<td>\n\n```python\n>>> data[\"answer\"] = \"spam\"\n>>> json.dumps(data)\n'{\"answer\": \"spam\"}'\n```\n\n</td>\n<td>\n\n```python\n>>> editor.root.editreplacevalue(0, \"spam\")\n>>> editor.dumps()\n'{ \"answer\": \"spam\" }'\n```\n\n</td>\n </tr>\n <tr>\n <td>Working with JSON files</td>\n<td>\n\n```python\n>>> with open(\"in.json\") as f:\n... data = json.load(f)\n...\n>>> with open(\"out.json\", \"w\") as f:\n... json.dump(data, f)\n...\n```\n\n</td>\n<td>\n\n```python\n>>> editor = json.loadf(\"in.json\")\n>>> editor.dumpf(\"out.json\")\n```\nOr use `jsoncgx.load()` and `jsoncgx.JSONEditor.dump()` with a file handle, like the standard module.\n</td>\n </tr>\n <tr>\n <td>Non unique name</td>\n<td>\n\n```python\n>>> data = json.loads(\n... '{ \"answer\": 42, \"answer\": \"spam\" }')\n>>> data[\"answer\"]\n'spam'\n```\n\n</td>\n<td>\n\n```python\n>>> editor = jsoncgx.loads(\n... '{ \"answer\": 42, \"answer\": \"spam\" }')\n>>> editor.root[\"answer\"][0]\n42\n>>> editor.root[\"answer\"][1]\n'spam'\n```\n\n</td>\n </tr>\n <tr>\n <td>Comments</td>\n<td>\n\n```python\n>>> data = json.loads(\n... '{ \"answer\": /* eggs and */ 42 }')\nTraceback (most recent call last):\n...\njson.decoder.JSONDecodeError: ...\n```\n\n</td>\n<td>\n\n```python\n>>> editor = jsoncgx.loads(\n... '{ \"answer\": /* eggs and */ 42 }')\n>>> editor.root.editreplacevalue(0, \"spam\")\n>>> editor.dumps()\n'{ \"answer\": /* eggs and */ \"spam\" }'\n```\n\n</td>\n </tr>\n</table>\n\n## What syntax does this parse exactly?\n\n[ECMA-404](https://ecma-international.org/wp-content/uploads/ECMA-404_2nd_edition_december_2017.pdf)\nwith the following additional lexical elements:\n* regex `//[^\\n]*\\n`, that is, the Unicode scalar sequence:\n * U+002F,\n * U+002F,\n * any amount of any scalars except U+000A,\n * U+000A.\n* lazy regex `/\\*.*\\*/`, that is, the Unicode scalar sequence:\n * U+002F,\n * U+002A,\n * any amount of any scalars except the sequence U+002A U+002F\n * U+002A,\n * U+002F.\n\nThose elements are considered like whitespace.\n\n## Architecture\n\n![jsoncgx architecture](architecture.png)\n\n## Changelog\n\n### V1.1:\n\n* `JSONNumber`, `JSONString`, `JSONBool`, and `JSONNull` have been replaced with\n `JSONBuiltin`, for easier integration.\n* `edit*()` methods that accepted `JSONValue` now also accept `int`, `float`,\n `str`, `bool`, and `None`. They are automatically turned into `JSONBuiltin`.\n",
"bugtrack_url": null,
"license": null,
"summary": "An overpowered JSON-with-comments parser with inplace edition",
"version": "1.1",
"project_urls": {
"Issues": "https://github.com/cigix/jsoncgx/issues",
"Repository": "https://github.com/cigix/jsoncgx"
},
"split_keywords": [
"json",
" jsonc",
" json with comments",
" json editor"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "74cf7b4915e4ce24811c4be32a6c425bfb1a4d6d70adae4aa621544c91db0453",
"md5": "bf291a4c5df461ffa5a625bb2dde7eec",
"sha256": "6e14449a67d538411936cf08a726790c3d934f69f7ecc48b0a6a01a0b2cfca26"
},
"downloads": -1,
"filename": "jsoncgx-1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bf291a4c5df461ffa5a625bb2dde7eec",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 35850,
"upload_time": "2024-05-11T17:44:23",
"upload_time_iso_8601": "2024-05-11T17:44:23.611976Z",
"url": "https://files.pythonhosted.org/packages/74/cf/7b4915e4ce24811c4be32a6c425bfb1a4d6d70adae4aa621544c91db0453/jsoncgx-1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9d74fd5c51ff08120e8ec8b55cf4ce57bef8774e04746524314308582f9046ab",
"md5": "6a4d858583799987214020449c9b2667",
"sha256": "1b3b736e6f7c4092dd5b8db2547cc47c78e2b577a436ddcff34214dc551f94a6"
},
"downloads": -1,
"filename": "jsoncgx-1.1.tar.gz",
"has_sig": false,
"md5_digest": "6a4d858583799987214020449c9b2667",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 34958,
"upload_time": "2024-05-11T17:44:25",
"upload_time_iso_8601": "2024-05-11T17:44:25.167650Z",
"url": "https://files.pythonhosted.org/packages/9d/74/fd5c51ff08120e8ec8b55cf4ce57bef8774e04746524314308582f9046ab/jsoncgx-1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-11 17:44:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cigix",
"github_project": "jsoncgx",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "jsoncgx"
}