diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-05-28 21:00:29 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-05-28 21:00:29 -0700 |
commit | 8f79bdd128e7ffcd471ad5f00e33a49619c41e6e (patch) | |
tree | 5b84236d77340fa0001d81064e33392e9410b325 /txr.1 | |
parent | 936314c70f9356db993cfbe781919026e2df042c (diff) | |
download | txr-8f79bdd128e7ffcd471ad5f00e33a49619c41e6e.tar.gz txr-8f79bdd128e7ffcd471ad5f00e33a49619c41e6e.tar.bz2 txr-8f79bdd128e7ffcd471ad5f00e33a49619c41e6e.zip |
json: tojson function.
* eval.c (eval_init): tojson intrinsic registered.
* lib.c (tojson): New function.
* lib.h (tojson): Declared.
* txr.1: Documented.
* share/txr/stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 66 |
1 files changed, 66 insertions, 0 deletions
@@ -71808,6 +71808,72 @@ etc. .SS* Data Interchange Support +.coNP Function @ tojson +.synb +.mets (tojson < obj <> [ flat-p ]) +.syne +.desc +The +.code tojson +function converts +.meta obj +into JSON notation, returned as a character string. + +If +.meta obj +is +.code json +macro syntax generated by the parser, or else generated programmatically in a compatible way, +then this is converted back into JSON syntax. + +Otherwise if +.meta obj +conforms to the conventions by which JSON objects are represented in Lisp, +it is converted to JSON syntax also. + +The behavior is unspecified if +.meta obj +or any component of +.meta obj +is an object incompatible with the JSON representation conventions. +An exception may be thrown. + +An object conforms to the JSON representation conventions if: +.RS +.IP 1. +It is one of the symbols +.codn nil , +.code t +or +.codn null , +which map to the JSON keywords +.codn false , +.code true +and +.codn null , +respectively. +.IP 2. +It is a floating-point number. +.IP 3. +It is a character string. +.IP 4. +It is a vector of JSON-conforming objects. +.IP 5. +It is a hash table whose keys and values are JSON-conforming objects. +.RE +.IP +Note that if unless the keys in a hash table are all strings, nonstandard JSON +is produced, since RFC 8259 requires JSON object keys to be strings. + +If the +.code flat-p +argument is present and has a true value, then the JSON is generated +without any line breaks or indentation. + +Otherwise, the JSON is potentially subject to such formatting. + +Even if the JSON data contains line breaks, it does not end in a line break. + .coNP Macro @ json .synb .mets (json [quote | sys:qquote] << object ) |