Hjson, the Human JSON. A data format that caters to humans and helps reduce the errors they make.
It supports #
, //
and /**/
style comments as well as avoiding trailing/missing comma and other mistakes. For details and syntax see hjson.org.
Hjson works with Python 2.5+ and Python 3.3+
The Python implementation of Hjson is based on simplejson. For other platforms see hjson.org.
-
pip install hjson
-
or download from https://pypi.python.org/pypi/hjson
import hjson
text = """{
foo: a
bar: 1
}"""
hjson.loads(text)
Result:
OrderedDict([('foo', 'a'), ('bar', 1)])
hjson.dumps({'foo': 'text', 'bar': (1, 2)})
Result:
{
foo: text
bar:
[
1
2
]
}
Note that this is probably not as performant as the simplejson version.
hjson.dumpsJSON(['foo', {'bar': ('baz', None, 1.0, 2)}])
Result:
'["foo", {"bar": ["baz", null, 1.0, 2]}]'
Use hjson.tool
to validate and convert.
python -m hjson.tool [FORMAT] [INFILE [OUTFILE]]
Formats:
-h
: print Hjson-j
: print formatted JSON-c
: print compact JSON
E.g. echo '{"json":"obj"}' | python -m hjson.tool
-
v1.5.0
- Added support for optional root braces
-
v1.4.1
- Added documentation, links.
-
v1.4.0
- First release.