NEWS: (December 2015) Version 2.2.4 was released!

Read about all the changes. (Notes for downstream package maintainers.)

About demjson and jsonlint

The demjson package is a comprehensive Python language library to read and write JSON; the popular language-independent data format standard.

It includes a command tool, jsonlint, that allows you to easily check and validate any JSON document, and spot any potential data portability issues. It can also reformat and re-indent a JSON document to make it easier to read.

(If you use C you may be intested in my patches for the Jansson C library for Big-Num support)

Quick example (code)

>>> import demjson

>>> demjson.encode( ['one',42,True,None] )    # From Python to JSON

>>> demjson.decode( '["one",42,true,null]' )  # From JSON to Python
['one', 42, True, None]

>>> cfg = demjson.decode_file( "config.json" )  # Read JSON from a file

Quick example (jsonlint)

$ jsonlint my.json

my.json:1:8: Error: Numbers may not have extra leading zeros: '017'
   |  At line 1, column 8, offset 8
my.json:4:10: Warning: Object contains same key more than once: 'Name'
   |  At line 4, column 10, offset 49
   |  Object started at line 1, column 0, offset 0 (AT-START)
my.json:9:11: Warning: Integers larger than 53-bits are not portable
   |  At line 9, column 11, offset 142
my.json: has errors

If you add a --stats option it will output detailed statistics. See example JSON statistics.

Quick example — reformatting or pretty-printing

You can use jsonlint to reformat a JSON file in an easier to read format with extra white-space and indentation.

$ echo '{"one": {"star":"\u2605","ace":[2,3, true]}, "two":"hello"}' | jsonlint -f
  "one" : { 
      "ace" : [ 
      "star" : "★"
  "two" : "hello"

If you don't want it to emit Unicode charaters add a -e ascii option.

Quick example — compressing / minifying

You can use jsonlint to remove all the unnecessary white-space from a JSON file:

$ cat pretty_printed.json | jsonlint -F
{"one":{"ace":[2,3,true],"star":"★"},"two":"hello"}     # No newline at end


See the demjson license page for complete details...

This is Free Software, licensed under the terms of the GNU LGPL version 3 or later.

This basically means you are completely free to use it however you want (even in proprietary systems) for any purpose. However, if you make modifications to it and you redistribute it to others, then you must make your modifications to this software public and also release it under the same license terms. Read the license text for all the details.

Older versions may have been released under a different license; be sure to read the LICENSE.txt file that is included in each package.