Expand description
Order-preserving JSON tree and the Gson-compatible writer (DRND-05).
Gateway-written JSON is Gson pretty output. Render passes files through
as bytes; this module only decides whether a file may be rewritten
(uuid injection in 21-07) and gives the secret lint (21-08) a tree to
walk. A file is JsonClass::GatewayFormat when
write(parse(bytes)) == bytes, otherwise JsonClass::Opaque and render
never mutates it.
§The tree
Node keeps object members in source order (never sorted: the spec’s
“sorted keys” is wrong, ROADMAP constraint) and keeps every number,
true, false and null as its original lexeme (Node::Lit), so
2.50, 1.0E10, -0.0 and 18446744073709551616 survive unchanged.
serde_json runs with raw_value only; preserve_order and
arbitrary_precision stay off.
§The writer: Gson pretty, HTML-safe
2-space indent, ": " between key and value, one member or element per
line, {} and [] for empty containers, no trailing newline. Strings
and keys are escaped as Gson’s JsonWriter does with HTML-safe on
(ESC(hhhh) below is the six characters backslash, u, four lowercase
hex digits):
| Character | Written as |
|---|---|
" and \ | backslash-escaped |
| TAB, BS, LF, CR, FF | backslash then t, b, n, r, f |
| other code points below U+0020 | ESC(00hh) |
< > & = ' | ESC(003c) ESC(003e) ESC(0026) ESC(003d) ESC(0027) |
| U+2028, U+2029 | ESC(2028), ESC(2029) |
| everything else, DEL and non-ASCII included | raw UTF-8 |
Raw UTF-8 for non-ASCII is decision CD4 (21-LIVE-CAPTURES.md): the 8.3.6
gateway wrote Température ✓ unescaped.
Errors are Strings carrying serde_json’s line/column text or a key
name, never a value (T-21-22).
Enums§
Constants§
- JSON_
MAX_ BYTES - Per-file size cap for a
.jsonmember (16 MiB). Larger files are refused before any parse (T-21-19). - MAX_
DEPTH - Deepest container nesting
parseaccepts (serde_json’s own default recursion limit). Checked by a linear scan before the recursive build, so hostile nesting can neither overflow the stack nor cost O(depth x size) (T-21-19).