Skip to main content

JSON for Humans, allows comments and is less error prone.

Project description

hjson-py

Hjson, the Human JSON. A configuration file 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 http://laktak.github.io/hjson.

Hjson works with Python 2.5+ and Python 3.3+ (forked from simplejson)

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

See the simplejson docs: http://simplejson.readthedocs.org/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hjson-1.4.0.zip (56.5 kB view details)

Uploaded Source

File details

Details for the file hjson-1.4.0.zip.

File metadata

  • Download URL: hjson-1.4.0.zip
  • Upload date:
  • Size: 56.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for hjson-1.4.0.zip
Algorithm Hash digest
SHA256 20558ace29fb7517de8b549c860f023b1653746a960c3f8d66bd0fc2e01d07b7
MD5 d7ab1b8a50221d41d7bf3b9fecd4ee48
BLAKE2b-256 032a0010feab54e2e571bc058ce2f78db57ab819d7d5ddfb50227cda14967ff4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page