9.2 JSON Printing and Parsing

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.

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.