Python module for JSON data encoding, including jsonlint. See the project Wiki here on Github. Also read the README at the bottom of this page, or the project homepage at
http://deron.meranda.us/python/demjson/

Under Python3 the sys.stdout file object is open in text mode,
not binary mode. So to write raw bytes to it (as is done when
using jsonlint's -f or -F options), you must use the underlying
raw file object (sys.stdout.buffer) that bypasses the text
mode wrapper.

README.md

demjson

demjson is a Python language module for
encoding, decoding, and syntax-checking JSON
data. It works under both Python 2 and Python 3.

It comes with a jsonlint script which can be used to validate
your JSON documents for strict conformance to the JSON specification,
and to detect potential data portability issues. It can also reformat
or pretty-print JSON documents; either by re-indenting or removing
unnecessary whitespace.

What's new

Version 2.2.4 fixes problem with jsonlint under Python 3 when
trying to reformat JSON (-f or -F options) and writing the output to
standard output.

Version 2.2.3 fixes incorrect return values from the "jsonlint"
command. Also fixes a minor problem with the included unit tests in
certain Python versions.

There are many more changes, as well as a small number of backwards
incompatibilities. Where possible these incompatibilities were kept
to a minimum, however it is highly recommended that you read the
change notes thoroughly.

Why use demjson?

I wrote demjson before Python had any JSON support in its standard
library. If all you need is to be able to read or write JSON data,
then you may wish to just use what's built into Python.

However demjson is extremely feature rich and is quite useful in
certain applications. It is especially good at error checking
JSON data and for being able to parse more of the JavaScript syntax
than is permitted by strict JSON.

A few advantages of demjson are:

It works in old Python versions that don't have JSON built in;

It generally has better error handling and "lint" checking capabilities;

It will automatically use the Python Decimal (bigfloat) class
instead of a floating-point number whenever there might be an
overflow or loss of precision otherwise.

It can correctly deal with different Unicode encodings, including ASCII.
It will automatically adapt when to use \u-escapes based on the encoding.

It generates more conservative JSON, such as escaping Unicode
format control characters or line terminators, which should improve
data portability.

In non-strict mode it can also deal with slightly non-conforming
input that is more JavaScript than JSON (such as allowing comments).

It supports a broader set of Python types during conversion.

Installation

To install, type:

python setup.py install

or optionally just copy the file "demjson.py" to whereever you want.
See "docs/INSTALL.txt" for more detailed instructions, including how
to run the self-tests.

More information

See the files under the "docs" subdirectory. The module is also
self-documented, so within the python interpreter type:

import demjson
help(demjson)

or from a shell command line:

pydoc demjson

The "jsonlint" command script which gets installed as part of demjson
has built-in usage instructions as well. Just type:

License

LGPLv3 - See the included "LICENSE.txt" file.

This software is Free Software and is licensed under the terms of the
GNU LGPL (GNU Lesser General Public License). More information is
found at the top of the demjson.py source file and the included
LICENSE.txt file.

Releases prior to 1.4 were released under a different license, be
sure to check the corresponding LICENSE.txt file included with them.