mochi/output

Internal typed JSON value used by the encoder.

Resolvers and field extractors hand Dynamic to the encoder. Rather than brute-forcing the runtime shape with a cascade of decoders on every node, we classify once with dynamic.classify and convert into this tree. The JSON encoder then walks the tree directly — no re-classification, no re-parsing of its own output for pretty printing, no silent fallbacks when something doesn’t fit.

Types

pub type EncodeError {
  UnsupportedValue(path: String, kind: String)
}

Constructors

  • UnsupportedValue(path: String, kind: String)

    The encoder hit a Dynamic value whose runtime shape it can’t represent in JSON (a tuple, function, pid, etc). path is the JSON pointer to the offender, kind is dynamic.classify of the value.

pub type Value {
  VBool(Bool)
  VInt(Int)
  VFloat(Float)
  VString(String)
  VNull
  VList(List(Value))
  VObject(List(#(String, Value)))
}

Constructors

  • VBool(Bool)
  • VInt(Int)
  • VFloat(Float)
  • VString(String)
  • VNull
  • VList(List(Value))
  • VObject(List(#(String, Value)))

Values

pub fn from_dynamic(
  value: dynamic.Dynamic,
) -> Result(Value, EncodeError)

Convert a Dynamic into the typed value tree, surfacing unsupported shapes as errors instead of silently dropping them.

Search Document