diff options
-rw-r--r-- | lib.c | 5 | ||||
-rw-r--r-- | txr.1 | 44 |
2 files changed, 36 insertions, 13 deletions
@@ -12592,6 +12592,11 @@ static void out_json_str(val str, val out) case '\t': put_string(lit("\\t"), out); break; + case '<': + put_char(chr(ch), out); + if (*cstr == '/') + put_char(chr('\\'), out); + break; case 0xDC00: put_string(lit("\\u0000"), out); break; @@ -12417,7 +12417,11 @@ symbol is bound as a macro, which is expanded when a .code #J expression is evaluated. -The following extensions to JSON are supported. +The following remarks indicate special treatment and extensions in the +processing of JSON. Similar remarks regarding the production of JSON are +given under the +.code tojson +function. When an invalid UTF-8 byte is encountered inside a JSON string, its value is mapped into the code point range U+DC01 to U+DCFF. That byte is consumed, and @@ -12431,18 +12435,6 @@ The JSON escape sequence .code "\eu0000" denoting the U+0000 NUL character is also converted to U+DC00. -When a JSON string is output, any code points U+DC01 through U+DCFF occurring -in that string are assumed to denote raw bytes to be output, without -escaping. The code point U+DC00 produces the -.code "\eu0000" -escape syntax. This behavior is different from \*(TL literals, which, on -output, simply render these code points using -.code "\ex" -escape sequences. Rationale: this is because JSON is considered an external format. -The requirements are intended to reproduce the original byte sequence, if -possible, rather than JSON syntax which will produce the same \*(TX object -if read back by \*(TX. - \*(TL does not impose the restriction that the keys in a JSON object must be strings: .code "#J{1:2,true:false}" @@ -71917,6 +71909,32 @@ 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. +When a JSON string is output, any code points U+DC01 through U+DCFF occurring +in that string are assumed to denote raw bytes to be output, without +escaping. The code point U+DC00 produces the +.code "\eu0000" +escape syntax. This behavior is different from \*(TL literals, which, on +output, simply render these code points using +.code "\ex" +escape sequences. Rationale: this is because JSON is considered an external format. +The requirements are intended to reproduce the original byte sequence, if +possible, rather than JSON syntax which will produce the same \*(TX object +if read back by \*(TX. + +If the character sequence +.code "</" +occurs in the string, the slash is escaped, such that the sequence +is rendered as +.codn "<\e/" . +Instances of the +.code / +(forward slash, solidus) occurs not preceded by +.code < +(less than) are unescaped. Rationale: this allows for safe embedding +of the resulting JSON into HTML +.code script +tags. + .coNP Function @ get-json .synb .mets (get-json >> [ source |