HJSON,JSON的用户界面。
hjson的Python项目详细描述
安装
- pip install hjson
- 或从https://pypi.python.org/pypi/hjson 下载
命令行
Usage: hjson [options] hjson [options] <input> hjson (-h | --help) hjson (-V | --version) Options: -h --help Show this screen. -j Output as formatted JSON. -c Output as JSON. -V --version Show version.
例如echo '{"json":"obj"}' | hjson
用法
importhjson
解码hjson
text="""{ foo: a bar: 1 }"""hjson.loads(text)
结果:
OrderedDict([('foo','a'),('bar',1)])
编码python对象层次结构
hjson.dumps({'foo':'text','bar':(1,2)})
结果:
{ foo: text bar: [ 1 2 ] }
编码为json
注意,这可能没有simplejson版本的性能好。
hjson.dumpsJSON(['foo',{'bar':('baz',None,1.0,2)}])
结果:'["foo", {"bar": ["baz", null, 1.0, 2]}]'