PyJSON5#

A JSON5 serializer and parser library for Python 3.5 and later.

The serializer returns ASCII data that can safely be used in an HTML template. Apostrophes, ampersands, greater-than, and less-then signs are encoded as unicode escaped sequences. E.g. this snippet is safe for any and all input:

"<a onclick='alert(" + encode(data) + ")'>show message</a>"

Unless the input contains infinite or NaN values, the result will be valid JSON data.

All valid JSON5 1.0.0 and JSON data can be read, unless the nesting level is absurdly high.

Installation#

$ pip install pyjson5

Table of Contents#

Quick Summary#

decode(data[, maxdepth, some])

Decodes JSON5 serialized data from an str object.

decode_buffer(obj[, maxdepth, some, wordlength])

Decodes JSON5 serialized data from an object that supports the buffer protocol, e.g. bytearray.

decode_callback(cb[, maxdepth, some, args])

Decodes JSON5 serialized data by invoking a callback.

decode_io(fp[, maxdepth, some])

Decodes JSON5 serialized data from a file-like object.

load(fp, **kw)

Decodes JSON5 serialized data from a file-like object.

loads(s, *[, encoding])

Decodes JSON5 serialized data from a string.

encode(data, *[, options])

Serializes a Python object as a JSON5 compatible string.

encode_bytes(data, *[, options])

Serializes a Python object to a JSON5 compatible bytes string.

encode_callback(data, cb[, supply_bytes, ...])

Serializes a Python object into a callback function.

encode_io(data, fp[, supply_bytes, options])

Serializes a Python object into a file-object.

encode_noop(data, *[, options])

Test if the input is serializable.

dump(obj, fp, **kw)

Serializes a Python object to a JSON5 compatible string.

dumps(obj, **kw)

Serializes a Python object to a JSON5 compatible string.

Options

Customizations for the encoder_*(...) function family.

Json5EncoderException

Base class of any exception thrown by the serializer.

Json5DecoderException([message, result])

Base class of any exception thrown by the parser.

Compatibility#

At least CPython / PyPy 3.5, and a C++11 compatible compiler (such as GCC 5.2+) is needed.


Glossary / Index