Navigation Menu

Skip to content

pombreda/hjson-py

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hjson-py

Build Status PyPI version

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.

Installation

Usage

import hjson

Decoding Hjson

text = """{
  foo: a
  bar: 1
}"""

hjson.loads(text)

Result:

OrderedDict([('foo', 'a'), ('bar', 1)])

Encoding Python object hierarchies

hjson.dumps({'foo': 'text', 'bar': (1, 2)})

Result:

{
  foo: text
  bar:
  [
    1
    2
  ]
}

Encoding as JSON

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]}]'

From the Commandline

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

API

hjson-py documentation

Changes

  • v1.5.0

    • Added support for optional root braces
  • v1.4.1

    • Added documentation, links.
  • v1.4.0

    • First release.

About

Human JSON (Hjson) implementation for Python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%