demjson.py and jsonlint

This is a comprehensive python language binding to the JSON language-independent data encoding standard, which is often used as a simpler subtitute for XML in AJAX-based web applications.

Regarding Python 3.0: The newest 3.0 version of Python now includes built-in support for JSON (by absorbing the "simplejson" module by Bob Ippolito). However as many find my module useful, and with features that the competing modules don't have, I will continue to support demjson for the forseeable future.

Version 1.4 was released on 2008-12-17. It is identical to version 1.3 released on 2008-03-19, except for a change in licensing terms. Read the list of changes.

Current version:

Requirements

This module is written entirely in python and requires no additional components or modules apart from those in the standard python library. It requires at least python version 2.3 or higher (but not Python 3000 yet).

Note for full Unicode support of non-BMP characters, your Python interpreter must have been compiled for UCS-4 support.

Support for the Decimal type for extreme-precision floating point numbers requires Python 2.4 or greater. Only float is supported under Python 2.3.

Improvements and changes in version 1.4

These are the most important changes in this release. For full details read the comprehensive change notes.

Improvements and changes in version 1.3

Known issues/bugs:

The following are the known problems with this release, and what I plan to do about them.

To report bugs or suggest changes, please email me. My contact information can be found on my home page.

Older versions:

License

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.

See also

Standards:

Other python implementations:

Read my Comparing JSON Modules report.

Other:

Quick example

>>> import demjson

>>> demjson.encode( ['one',42,True,None] )
u'["one",42,true,null]'

>>> demjson.decode( u'["one",42,true,null]' )
['one', 42, True, None]

Module features

This implementation attempts to be as closely conforming to the JSON specification (published as IETF RFC 4627) as possible. It can also be used in a non-strict mode where it is much closer to the JavaScript/ECMAScript syntax (published as ECMA 262).

Now comes with a jsonlint tool which can be used to validate your JSON documents for strict conformance to the RFC specification; as well as to reformat them, either by re-indenting or for minimal/canonical JSON output.

It has a strict and non-strict mode when parsing JSON text, and many levels in between. The strict mode only allows input which precisely meets the syntax requirements of RFC 4627 (JSON) and no more (it is so strict it could be used as a lint-style validation checker for your JSON encodings). But when used in its non-strict mode it is much more liberal in what it accepts by following more closely the JavaScript language specification rather than the more restrictive JSON. When producing JSON though this module is, almost always, strictly conforming. — The default mode is non-strict.

Some of the distinguishing features of this module are:

Each of the features (behaviors) listed above which work only when in a non-strict mode can be allowed or prevented individually. Thus for example you can choose to allow comments but still prevent the use of hexadecimal numbers.

Coming later

I am working on a new version. Besides bug fixes, I hope to improve performance significantly.

Does not work with Python 3000 (aka 3.0) yet. I am working on a native rewrite which will work properly in the new language (including using the correct semantics for bytes and strings).