Introduction
jsown is a high-performance Common Lisp JSON parser. Its aim is to allow for the fast parsing of JSON objects into Lisp s-expressions, which can then be edited or accessed like any other Lisp code, and re-encoded into JSON.
Installation
jsown
is available via Quicklisp. To install, evaluate:
Basic Usage
Assume we have a dynamic variable *json-string*
which, as the name helpfully suggests, contains an encoded JSON string:
To convert this JSON string into jsown's internal representation, use the PARSE
function:
jsown decodes JSON Objects into lists whose first member is the :OBJ
keyword symbol. Each subsequent sub-list represents a key-value association as a CONS
-ed pair; thus, for each sub-list, the members of the JSON object can be accessed with CAR
and CDR
to retrieve the key and value, respectively.
JSON Arrays are also decoded into lists, though without the leading :OBJ
symbol. Rather than CONS
-ed pairs, decoded arrays are proper lists (lists whose last element is itself a list). This can result in seemingly ambiguous Lisp representations of data; for example, in the above code, the key-value pair "baz": [1, 2, "blub"]
is parsed as ("baz" 1 2 "blub")
. This may appear like a decoded array at first, but as this is a sub-list of an object, it can be separated into key and value by the usual combination of CAR
and CDR
.
From here, we can convert this internal representation back into valid JSON using the TO-JSON
method:
We can also use the VAL
function to retrieve values from jsown objects:
External Links
The project's repository on GitHub