I also think there's a point to having a mix of minimalist SRFIs and
maximalist SRFIs (maximalism is a word in some circles).
Agreed, and this will still be fairly minimal even with a pretty printer.
The point is that there's a constant need to store JSON in files and to
view those files in a text editor, terminal, web browser or what have
you. It has made my work much easier when I store files pretty-printed
(and keys sorted). Diffs also become human-readable.
Good points all.
Isn't JSON pretty-print just JSON write with custom delimiters (most
notably, newline instead of space) and a non-zero indent width?
Yes. I think it would be a mistake for the SRFI to prescribe some particular pp algorithm, though.
Something I've also wanted in other languages is the ability to put JSON
keys in a convenient application-specific order. Alphabetical order is
not always easiest to read. This can be done by taking a procedure to
compare two keys; it can be symbol<? by default.
I see what you mean, but we don't have a good mechanism for creating such ordering predicates. The enum machinery I have a pre-SRFI for will allow it: an enum object has a distinct type and four instance variables: the enum type, the symbol name, the ordinal number, and the arbitrary value.
`json-write-line` may be the most natural name for a JSON Lines writer
(Scheme has `write-char` and `write-string`, and Common Lisp has
`write-line`).'
I think json-write would make the most sense here. Scheme doesn't have a standard name for write-then-newline like writeln in many languages or CL print.
`json-write-line` and `json-write-sequence` would be my favorite
combination, but AFAICT "sequence" means the sequence of many "texts",
not an individual text, so it would be incorrect terminology.
That's why I think json-write and json-write-sequence-text are best.
Finally, one could add a `json-pretty-write` or `json-pretty-print` (or
`json-indented-write` or `json-custom-write`, etc.)
I like json-pp for analogy with pp. pp should not be called pretty-print, because it is a case in which terseness is actually important. We could just say that json-pp is the same as json-write, but may introduce additional whitespace for better human readability. That allows a minimal implementation where memory is tight to make it the same as json-write.
John Cowan
http://vrici.lojban.org/~cowan xxxxxx@ccil.orgWhen I wrote it I was more than a little febrile with foodpoisoning
from an antique carrot that I foolishly ate out of an illjudged faith
in the benignancy of vegetables. --And Rosta