mochi/json
JSON serialization for Dynamic values.
The encoder converts Dynamic into the typed value tree in mochi/output
once, then walks the tree. Errors propagate instead of getting silently
swallowed as null.
Types
pub type EncodeError =
output.EncodeError
Values
pub fn describe_error(err: output.EncodeError) -> String
Human-readable description of an encode failure.
pub fn encode(
value: dynamic.Dynamic,
) -> Result(String, output.EncodeError)
Encode a Dynamic value to a compact JSON string.
Returns an error when the value contains a runtime shape that can’t be
represented in JSON (functions, tuples, pids, references, …) — instead
of silently emitting null for it.
pub fn encode_pretty(
value: dynamic.Dynamic,
indent: Int,
) -> Result(String, output.EncodeError)
Encode a Dynamic value to a pretty-printed JSON string with the given indent width. Walks the value tree directly — does not re-parse JSON.