JsonComment
raw JSON → 0.4.2 verified Mon Apr 27 auth: no python
A wrapper to JSON parsers allowing comments, multiline strings and trailing commas. Current version 0.4.2, supports Python >=3.3. Suitable for config files with human-friendly JSON extensions.
pip install jsoncomment Common errors
error AttributeError: module 'jsoncomment' has no attribute 'loads' ↓
cause Importing the module directly instead of the class.
fix
Use: from jsoncomment import JsonComment; parser = JsonComment(); parser.loads(...)
error jsoncomment.JsonComment not found ↓
cause Incorrect import path.
fix
Use: from jsoncomment import JsonComment
Warnings
gotcha JsonComment does not strip comments from strings; if a string value contains '//' or '/*', it may be misinterpreted. ↓
fix Ensure comment syntax is not inside string literals.
gotcha The library relies on Python's built-in json module; it does not validate JSON strictly and may accept malformed input. ↓
fix Always validate output if parsing untrusted input.
Imports
- JsonComment wrong
import jsoncommentcorrectfrom jsoncomment import JsonComment
Quickstart
from jsoncomment import JsonComment
json_str = '''
{
"name": "test",
/* comment */
"value": 42
}
'''
parser = JsonComment()
data = parser.loads(json_str)
print(data)