Skip to main content

Module json

Module json 

Source
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 null becomes Value::Null. Non-UTF-8 input fails with Error::InvalidUtf8, and any syntax error becomes Error::Parse with the failing position.
  • is_format_supported returns Some(true) when the bytes parse as JSON, else Some(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 json format: standard JSON into a source-located value tree.

Functions§

unparse
Serialize a Value tree into pretty-printed JSON (2-space indent).