A wrapper to JSON parsers allowing comments, multiline strings and trailing commas
A wrapper to JSON parsers allowing comments, multiline strings and trailing commas
JSON Comment allows to parse JSON files or strings with:
This package works with any JSON parser which supports:
load(fp, ...)
to parse filesloads(s, ...)
to parse stringsby adding a preprocessor to these calls.
#
, ;
and //
are for single line comments/*
and */
enclose multiline commentsInline comments are not supported
Any string can be multiline, even object keys.
"""
, like in python\\n
loadf(path, *args, default = None, **kwargs)
Opens a JSON file with comments. Allows a default value if loading or parsing fails
dumpf(json_obj, path, *args, indent=4, **kwargs)
Saves a JSON file with indentation
pip install jsoncomment
OR
python setup.py install
from jsoncomment import JsonComment
string = "[]"
json = JsonComment()
json_obj = json.loads(string)
Added in the /examples directory
#
, ;
, //
and /*
may be preceded only by whitespaces or tabs on the same line*/
may be followed only by whitespaces or tabs on the same lineSource code available with MIT license on Bitbucket.
Added in top level __init__.py
API is split in:
* `User Interface` for common use
* `Developer Interface` exposing some internals that could be useful
For each item ( function or class ), there are 2 blocks of comments, above and below item definition:
* The top describes the return values
* The bottom describes the item and call variables
If call variables have defaults or use duck typing, every allowed value is described
Example:
# return_value
# description
from .some_module import SomeClass
# SomeClass description
# (
# variable_1,
# description
# variable_2 = something,
# description
# = Default
# description of default value ( something )
# = something_2
# description of alternate form ( duck typing )
# )
describes return_value = SomeClass(variable_1, variable_2 = current_value)
Gaspare Iengo @ email