baml.json.to_json
Serializes any BAML value to its `json` representation, dispatching on the value's runtime type.
Signature
Serializes any BAML value to its json representation, dispatching on the
value's runtime type.
The untyped spelling of from<T> — same walk, same baml.ToJson override
handling at every depth, same output. Only the signature differs: unknown
in place of a type parameter, which makes it callable where no static type
is available to instantiate from<T> with, and callable by name from a
host.
Prefer from<T> in BAML code. It is what a bare v.to_json() desugars to,
and it keeps the argument's type at the call site instead of erasing it to
unknown. This one exists so to_string and engine-side callers have a
non-generic symbol to bind.
Throws
baml.json.SerializationErrorif any value in the graph has no JSON form. Seefrom<T>for the rendering rules.
Source:<builtin>/baml/ns_json/json.bamlbytes 4530–4619