baml.json.serialize

Serializes `v` to JSON text, honoring `baml.ToJson` overrides on classes (via `to_json`). Equivalent to `to_string(v)`.

Reference version

Signature

function baml.json.serialize<T>(v: T) -> string throws baml.json.SerializationError

Serializes v to JSON text, honoring baml.ToJson overrides on classes (via to_json). Equivalent to to_string(v).

For a host that wants to print a target's return value as JSON while still respecting class-level to_json overrides. From BAML, call to_string directly; nothing here adds behaviour.

Throws

  • baml.json.SerializationError if any value in the graph has no JSON form; see from<T>.

Source:<builtin>/baml/ns_json/json.bamlbytes 1920619821