# schema/from-value
Validate and convert a value into a real `%Type{...}` tagged map.
Missing fields are filled from `:default`, fields with `:coerce true` are
converted (`"8080"` → `8080`, `"true"` → `true`, `"open"` → `:open`),
`:many` values are wrapped into vectors, and nested `:Type`/`:of` values
are converted recursively. This is the entry point for turning parsed
Deft/JSON/YAML/XML data into typed values.
## Syntax
[schema/from-value $type $value ?opts]
## Parameters
- `$type` — a type name (keyword or string), e.g. `:Order`
- `$value` — the map to convert
- `?opts` — optional options map: `:strict true` (unknown keys are errors),
`:all true` (collect every error)
## Examples
deftype Item %{ :sku %{:type :string :required true} :qty %{:type :number :coerce true} } deftype Order %{ :id %{:type :string :required true} :items %{:type :list :of :Item :many true} :status %{:type :keyword :coerce true} } set raw %{:id "A1" :items @{%{:sku "tea" :qty "2"}} :status "open"} set r [schema/from-value :Order $raw] [ok? $r] # => true set order [get $r :value] [type $order] # => "Order" [type [nth $order~items 0]] # => "Item" [nth $order~items 0]~qty # => 2 $order~status # => :open
Parsed-document pipeline:
set text [unwrap [fs/read "config.dft"]] set typed [schema/from-value :Server [deft/parse $text]] if [err? $typed] { echo [get $typed :path] [get $typed :message] }
Union-typed fields (`defunion`) accept any variant; the variant map is
converted against its own type and keeps its concrete tag.
## Returns
`%Ok{:value %Type{...}}` on success. On failure,
`%Err{:path @{...} :message "..."}` (or `%Err{:errors ...}` with
`:all true`) with no partial value. Extra input keys are preserved on the
output unless `:strict true`.
## See Also
`schema/validate`, `deftype`, `deft/parse`, `json/parse`, `yaml/load`