Reference · reference

json module

1 min read · 2026-09-02 · config-weave 0.1.0

use json parses and serializes JSON over the Value type. config-weave registers it from wscript-std. Only parse can fail; it returns Result[Value, string]. Serialization sorts map keys, so the same value always produces the same text and a rewritten file only changes when its content does.

parse

rust
json::parse(text: string) -> Result[Value, string]

Parses JSON text into a Value. Objects become maps, arrays become lists and null becomes Value::Null.

to_string and to_string_pretty

rust
json::to_string(value: Value) -> string
json::to_string_pretty(value: Value) -> string

Serializes a Value as compact JSON, or as indented JSON. Keys are emitted in sorted order.

rust
use fs
use json

let cfg = json::parse(fs::read("/etc/app/config.json")?)?
let enabled = match cfg.get("enabled") {
    Some(v) => v.as_bool().unwrap_or(false),
    None => false,
}