Omnist logo Omnist Tutorial Step 8 of 15

Materialization

Upgrade untyped leaves (a JSON string) to the type a schema declares.

Without a schema, a reader's leaves are exactly whatever the format's own native parser produces — JSON has no date type, so a date always comes back as a plain string. Pass schema= to a reader to upgrade leaves to match what the schema declares, whenever the conversion is value-exact:

from omnist import parse_schema, Doc

s = parse_schema('record R { "d": date }\nroot R')
raw = Doc.from_json('{"d": "2024-01-01"}')                 # no schema
mat = Doc.from_json('{"d": "2024-01-01"}', schema=s)      # schema-directed
type(raw.get_one("d").value), raw.get_one("d").value
type(mat.get_one("d").value), mat.get_one("d").value
Output
raw:          <class 'str'> 2024-01-01
materialized: <class 'datetime.date'> 2024-01-01

The Document's shape is unchanged either way — materialization only ever upgrades a leaf's type, in place, never restructures anything.

Learn more