Skip to content
CryoCryo home
Stdlibjson

parser

import std::json::parser; · source

Parsing

function parse(text: Str) -> Result<JsonValue, JsonError>;
const MAX_DEPTH: u64 = 256;

parse parses a complete document. Trailing whitespace is fine; trailing anything else is TrailingData.

The parser is single-pass recursive descent over a borrowed Str, and it is RFC 8259 strict: no trailing commas, no unquoted keys, no comments. String literals decode \X and \uXXXX escapes, and UTF-16 surrogate pairs are recombined; a lone surrogate is InvalidUnicode.

MAX_DEPTH caps combined object and array nesting at 256. The default is generous for hand-authored data and tight enough that a malicious megabyte of [[[...]]] cannot exhaust the stack.

The Parser struct behind parse is public but is an implementation detail; drive the free function.