/json-with-comments

JSON with Comments for Python

Primary LanguagePythonMIT LicenseMIT

JSON with Comments for Python

pypi version Python package Python Versions

Features

  • load(), loads()
    • Remove single line (//) and block comments (/* */)
    • Remove trailing commas from arrays and objects
  • dump(), dumps()
    • Add comments
    • Add trailing commas

Usage

pip install json-with-comments
>>> import jsonc
>>> jsonc.loads("{// comment \n}")
{}
>>> jsonc.loads("{/* comment */}")
{}
>>> jsonc.loads('{"spam": "ham // egg" /* comment */}')
{'spam': 'ham // egg'}
>>> jsonc.loads('{"spam": /* comment */"ham /* egg */"}')
{'spam': 'ham /* egg */'}

And just like json module