baml.json.deserialize

Parses JSON text into a value of type `T`, honoring `baml.FromJson` overrides on classes (via `from_json<T>`). Equivalent to `from_json<T>(parse(s))`.

Reference version

Signature

function baml.json.deserialize<T>(s: string) -> T throws baml.json.ParseError | baml.json.DecodeError

Parses JSON text into a value of type T, honoring baml.FromJson overrides on classes (via from_json<T>). Equivalent to from_json<T>(parse(s)).

For a host that wants to coerce a JSON-shaped input (such as --json-args) into a typed BAML value while respecting class-level from_json overrides. from_string<T> is the structural path, which bypasses overrides.

Throws

  • baml.json.ParseError if s is not valid JSON.
  • baml.json.DecodeError if the parsed document does not fit T.

Source:<builtin>/baml/ns_json/json.bamlbytes 21368–21912