A wrapper to JSON parsers allowing comments, multiline strings and trailing commas
Likely abandoned. No release or commit for years (last release over 7 years ago).
pip install jsoncommentJson Comment
A wrapper to JSON parsers allowing comments, multiline strings and trailing commas
Dependencies
- Python 3.3+
- TODO NEW ADDITIONS
Optional
- ujson 1.30+
Description
JSON Comment allows to parse JSON files or strings with:
- Single and Multi line comments
- Multi line data strings
- Trailing commas in objects and arrays, after the last item
This package works with any JSON parser which supports:
load(fp, ...)to parse filesloads(s, ...)to parse strings
by adding a preprocessor to these calls.
Comments
#,;and//are for single line comments/*and*/enclose multiline comments
Inline comments are not supported
Multiline strings
Any string can be multiline, even object keys.
- Multiline strings start and end with
""", like in python - The preprocessor merges all lines to a single JSON standard string
- A single trailing space per line is kept, if present
- New line is not kept. To hard code new lines in the string, use
\\n
Custom Methods
File Load
loadf(path, *args, default = None, **kwargs)
Opens a JSON file with comments. Allows a default value if loading or parsing fails
File Save
dumpf(json_obj, path, *args, indent=4, **kwargs)
Saves a JSON file with indentation
Install
pip install jsoncomment
OR
- Download source
python setup.py install
Usage
from jsoncomment import JsonComment
string = "[]"
json = JsonComment()
json_obj = json.loads(string)
Examples
Added in the /examples directory
Limitations
#,;,//and/*may be preceded only by whitespaces or tabs on the same line