Skip to main content

Module text

Module text 

Source
Expand description

The text syntax: JSON, plus // and /* */ comments, trailing commas and unquoted keys (the part of JSON5 editors already understand).

parse keeps where every value is (Spans), so a schema error at entries[2].pages[0].item can point at its line. Typed values stay strings here — the schema decides what a string means.

Structs§

Doc
A parsed document: the value and where each of its parts is.
LineCol
A 1-based line and column (in characters).
Span
A byte range of the source.
Spans
Where each value of a parsed document is: the value’s span, its key’s (map entries), and its children’s, in the same order as the value’s.
SyntaxError
A syntax error.
Writer
Writes the text form piece by piece, without a Value in between. A list or map is given its length, then that many values (a map’s each after its key); it closes by itself after the last, so there are no end calls. The pretty form puts one entry per line.

Constants§

MAX_DEPTH
Deeper than this is an error, not a stack overflow.

Functions§

parse
Parses text.
parse_ref
Parses text straight to a borrowed value, the way a schema reads it: no positions, and nothing is allocated on the heap per value — strings without escapes point into text, lists and maps are in arena.
parse_value
Parses text, without the positions (faster).
to_string
value as compact text (typed values in their string forms).
to_string_pretty
value as text indented by two spaces, one entry per line.
with_comments
text’s value, its comments in it (see the module docs).
write_string
s as a JSON string literal.