From 1ad283f9ca8d2a0b1eb9b8406de4b33da6691099 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 29 May 2021 08:33:41 -0700 Subject: 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. --- lib.c | 24 ++++++------------------ txr.1 | 24 ++++++------------------ 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/lib.c b/lib.c index aafc933a..1d2c65b7 100644 --- a/lib.c +++ b/lib.c @@ -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) diff --git a/txr.1 b/txr.1 index b9196a05..cf692fd5 100644 --- a/txr.1 +++ b/txr.1 @@ -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 -- cgit v1.2.3