diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-05-29 08:33:41 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-05-29 08:33:41 -0700 |
commit | 12800700f93639c259757f0f9def1546d215ee95 (patch) | |
tree | 8d1c58396447148dec418f3dc9c5819083404d4a | |
parent | b3a49b161a6192d4b8c574f0cd7f9b16567cd834 (diff) | |
download | txr-12800700f93639c259757f0f9def1546d215ee95.tar.gz txr-12800700f93639c259757f0f9def1546d215ee95.tar.bz2 txr-12800700f93639c259757f0f9def1546d215ee95.zip |
json: tojson must not add #J prefix.
* lib.c (out_json_rec): In the CONS case, if ctx is null bail
and report and invalid object. This lets us call the function
with a null context.
(tojson): Do not support (json ...) syntax. Instead of
obj_print, pass the object directly to out_json_rec.
* txr.1: Do not mention handling json macro syntax.
Common leading text factored out of bulleted paragraphs section.
-rw-r--r-- | lib.c | 24 | ||||
-rw-r--r-- | txr.1 | 24 |
2 files changed, 12 insertions, 36 deletions
@@ -12644,7 +12644,7 @@ static void out_json_rec(val obj, val out, struct strm_ctx *ctx) } break; case CONS: - { + if (ctx != 0) { val sym = car(obj); if (sym == hash_lit_s) { val save_indent; @@ -13461,23 +13461,11 @@ val tostringp(val obj) val tojson(val obj, val flat) { - if (consp(obj) && eq(car(obj), json_s)) { - val ss = make_string_output_stream(); - if (default_null_arg(flat)) - set_indent_mode(ss, num_fast(indent_foff)); - obj_print(obj, ss, nil); - return get_string_from_stream(ss); - } else { - val json = cons(json_s, cons(quote_s, cons(obj, nil))); - val ss = make_string_output_stream(); - if (default_null_arg(flat)) - set_indent_mode(ss, num_fast(indent_foff)); - obj_print(json, ss, nil); - rcyc_pop(&json); - rcyc_pop(&json); - rcyc_pop(&json); - return get_string_from_stream(ss); - } + val ss = make_string_output_stream(); + if (default_null_arg(flat)) + set_indent_mode(ss, num_fast(indent_foff)); + out_json_rec(obj, ss, 0); + return get_string_from_stream(ss); } val display_width(val obj) @@ -71854,18 +71854,6 @@ 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 @@ -71873,10 +71861,10 @@ or any component of is an object incompatible with the JSON representation conventions. An exception may be thrown. -An object conforms to the JSON representation conventions if: +An object conforms to the JSON representation conventions if it is: .RS .IP 1. -It is one of the symbols +one of the symbols .codn nil , .code t or @@ -71888,13 +71876,13 @@ and .codn null , respectively. .IP 2. -It is a floating-point number. +a floating-point number. .IP 3. -It is a character string. +a character string. .IP 4. -It is a vector of JSON-conforming objects. +a vector of JSON-conforming objects. .IP 5. -It is a hash table whose keys and values are JSON-conforming objects. +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 |