ST-JSON ('ST' because it originated at Streamtech) is a Common Lisp library for encoding and decoding JSON values (as specified on json.org).
This library does mostly the same thing as CL-JSON, but is simpler and more precise about types (distinguishing boolean false, the empty array, and the empty object).
The library is available under a zlib-style license. It can be installed with asdf-install, or you can download the current release manually. The git repository can be checked out with:
git clone http://marijnhaverbeke.nl/git/st-json
The code is also on github.
Mail Marijn Haverbeke with any questions, bug reports, patches, etcetera. I'll set up some mailing list when there is a need.
strings, null to the keyword
:null, booleans to the
:false, arrays to
lists, and objects to a custom type
object). Since in CL boolean false, the empty list, and nullish
stuff is all usually represented by
nil, you will
sometimes have to selectively transform your values before writing
or after reading them. (The empty array is a truthy value in
nil for a boolean is bound
to get you into trouble.)
A type including only the values
:false. Useful in
function as-json-bool (value)
Convert a generalised boolean to a
function from-json-bool (value)
json-bool to a Lisp boolean.
A type containing only
function jso (&rest fields)
jso names both a function and a type.
an alist. The function is called with an even number of arguments,
which give the properties of the object and their values.
function getjso (key jso)
second value indicating whether the value was found (like
gethash). Can be used with
function getjso* (keys jso)
Takes a key of the form "a.b.c", generates a series of getjso calls that descend into the object and returns 'c'.
function mapjso (function jso)
method read-json (source &optional junk-allowed-p)
Reads a JSON value from an input stream or string.
nil, an error will
be raised if any non-whitespace characters are found after the
value. This error, and any other parsing errors, will have the type
function read-json-as-type (source type)
read-json, but also asserts that
the resulting value is of a given type, and raises an error of type
json-type-error if not.
function write-json (element stream)
Writes a value to a stream. Raises an error of type
json-write-error if a value for which no
method is defined is encountered.
function write-json-to-string (element)
write-json, but produces a
method write-json-element (element stream)
Generic function used to serialise values as JSON. You can specialise it for your own types, if needed.
Bind this to
t when writing JSON that
will end up in an HTML document. It prevents
'</script>' from occurring in strings by escaping
any slash following a '
<' character. Default value