Expand description
JSON parser (json feature).
Format: json
§Behaviour
- Parses standard JSON with source spans. Objects become maps, arrays become lists, and strings/numbers/booleans become the matching scalar values; integers and floats are distinguished.
- Every node — root, map values, and list items — carries its span as a
Location(line/column); for single-line input the line/column are omitted. - JSON
nullbecomesValue::Null. Non-UTF-8 input fails withError::InvalidUtf8, and any syntax error becomesError::Parsewith the failing position. is_format_supportedreturnsSome(true)when the bytes parse as JSON, elseSome(false).
§Example
use tanzim_parse::{Parse, json::Json};
use tanzim_source::SourceBuilder;
let source = SourceBuilder::new()
.with_source("file")
.with_resource("config.json")
.build()
.unwrap();
let value = Json::new()
.parse(&source, br#"{"host":"127.0.0.1"}"#)
.unwrap();
assert_eq!(
value.value().as_map().unwrap().get("host").unwrap().value().as_string().unwrap(),
"127.0.0.1"
);Structs§
- Json
- Parser for the
jsonformat: standard JSON into a source-located value tree.