Skip to main content

parse

Function parse 

Source
pub fn parse(src: &str) -> Result<Value, Json5Error>
Expand description

Parse a JSON5 source string with the shared default parser.

The parser is built once, on first use, and reused after that. Reuse is safe: Tabnas::parse takes &self and builds a fresh parse context per call, and Tabnas is Send + Sync, so concurrent callers share one installed grammar instead of each rebuilding it, which is what dominates a small parse.

Use make_with and parse_with instead when the parser needs configuring: that returns a fresh instance and leaves this one alone.

let value = tabnas_json5::parse("{ a: 1, b: [2, 3,], }")?;
assert_eq!(value.to_string(), r#"{"a":1,"b":[2,3]}"#);
assert_eq!(tabnas_json5::parse("").unwrap_err().code, "json5_empty");