FSet supports JSON printing and parsing by extending the existing
Jzon library. The support is in a separate system,
FSet/Jzon, to avoid adding a dependency if you’re not using it; to load it, do ql:quickload
"fset/jzon".
FSet/Jzon parses JSON into FSet collections — JSON arrays parse into FSet seqs, and by default, JSON objects parse into FSet replay maps — and can also print these in JSON format. Two other FSet representations for JSON objects are also available: plain maps and dynamic tuples.
A potential problem area has to do with the treatment of null, empty, and false values. On the one
hand, JSON distinguishes these, as null, [], and false respectively. On the
other, in Common Lisp, nil is often used for all three: a missing value, an empty list, or a
false boolean value. What to do about this depends on whether you’re using a map representation for
JSON objects or a tuple representation. The reason this matters is that in the tuple case,
slot-specific type information can be supplied to tell Jzon what to do; in the map case, it cannot.
null will parse as cl:null, [] will parse as the
empty seq, and false will parse as nil. So your code that processes a parsed
structure must handle cl:null; when generating structure for JSON printing, you must use
cl:null as a value when you want it to print as JSON null, and the empty seq when you
want it to print as [] — which of course will happen naturally if you use seqs in place of
lists.
[] will still parse as the empty seq, but null will
parse as nil. FSet assumes that you’ve supplied the correct types for your tuple keys; when printing, nil prints as false if the key is of
boolean type, and as null otherwise. So instead of having to generate the structure in an
unnatural way (for CL), you just have to declare your key types.
FSet/Jzon uses the map representation by default because it’s easier to get started with, but you might prefer tuples for serious work. Tuples are also more space-efficient than maps, but this is unlikely to matter unless you are processing massive quantities of data.