pub fn parse(src: &str) -> Result<Value, JsoncError>Expand description
Parse a JSONC source string with the shared default parser.
The engine is built once, on first use, and reused after that; reuse
is safe because Tabnas::parse takes &self and builds a fresh
parse context per call, and Tabnas is Send + Sync. Building the
grammar dominates a small parse, so this is what a caller with no
options should use. The TypeScript package and the Go module have no
package-level parse of their own; this one is the Rust convenience the
sibling crates all offer.
Use make or make_with instead when the parser needs
configuring: that returns a fresh instance and leaves this one alone.
A document that holds only trivia (whitespace and comments) has no
value. The TypeScript plugin returns undefined for it; the Rust
engine folds a top-level undefined into Value::Null at the end of
every parse, so here it is null, which is also what the Go port’s
nil serializes as.
let value = tabnas_jsonc::parse(r#"{ "a": 1, /* one */ "b": [2] }"#)?;
assert_eq!(value.to_string(), r#"{"a":1,"b":[2]}"#);
assert_eq!(tabnas_jsonc::parse("// only a comment")?, tabnas::Value::Null);