Expand description
JSON — parse, stringify, and read back — as blue’s own surface.
Pure computation with no host imports, so this is part of the runtime
unconditionally (the wasm32-unknown-unknown consumer keeps it). The
semantics are the substrate’s — tatara-lisp-script’s json.rs is the
reference, and these are deliberately the same shapes — adapted to what
blue can actually reach:
json_parse(s) → nil / bool / int / float / string / list / alist
json_stringify(v) → string
json_get(doc, key) → value at key, or nil (doc = alist or Map)
json_get_or(doc, key, default) → value at key, or default§Why objects are alists, not Maps
Value::Map is the representation that round-trips {} exactly — the
substrate proved that fix, and it is kept for the empty case — but a Map
has no reachable reader: every map primitive blue’s own surface could
spell is kebab-case (hash-map-get), and - is an operator in blue, so a
json_parse that produced Maps would hand blue a document it could not
open. Non-empty objects therefore parse to an association list of
[key value] 2-lists, which blue reads with car/cdr/nth. json_get
is the Rust-side reader, total over both shapes.
The cost is the same ambiguity the substrate records: a JSON array whose every element is a 2-list with a string first still stringifies as an object. Round-trip is exact for the shapes the fleet emits; the Map/List split is where a future migration lands if the map reader becomes reachable.
Functions§
- install_
json_ stdlib - Install blue’s JSON surface.
- json_
to_ value - Convert a
serde_json::Valueinto aValue. Objects become association lists of[key value]2-lists; the EMPTY object isValue::Map, the one representation that can say “object with no entries” and round-trip. - value_
to_ json - Convert a
Valueback into aserde_json::Value. Closures and native functions collapse tonull.