Skip to content

Schema & Data

The most important ASUN idea is that schema describes structure once, and data only supplies ordered values.

The Split

Schema:

asun
{name@str, age@int, active@bool}

Data:

asun
(Alice, 30, true)

Combined:

asun
{name@str, age@int, active@bool}:(Alice, 30, true)

For a list, write the schema once and then multiple tuples:

asun
[{name@str, age@int}]:
  (Alice, 30),
  (Bob,   25)

Schema Rules

Each field uses @ as the field binding marker. A scalar field may be written as:

text
name
name@type

Scalar hint names are only:

  • int
  • float
  • str
  • bool

Complex fields use the same @ as a required structural binding:

  • @{...} nested struct
  • @[type] array
  • @[{...}] array of structs

Examples:

asun
{profile@{id@int, name@str}}
{tags@[str]}
{attrs@[{key@str, value@str}]}

This means:

  • name and name@str produce the same structural layout
  • address@{...} and tags@[...] cannot drop @, because it binds the field to the nested schema

Field Names

Plain field names work for simple identifiers:

asun
{id, name, active}

Quoted field names are required when a field name contains spaces, starts with digits, or contains syntax characters:

asun
{"id uuid"@int, "65"@bool, "{}[]@\""@str}

Data Rules

Data is positional, not keyed. The first value matches the first field, the second value matches the second field, and so on.

Nested struct data uses nested tuples:

asun
{address@{city@str, zip@str}}:((Berlin, 10115))

Arrays use square brackets:

asun
{tags@[str]}:([rust, go, zig])

An empty slot represents null / missing:

asun
{id@int, score@float}:(1, )

What ASUN Does Not Do

Current ASUN text does not use inline object literals in the data section:

asun
{user@{id@int}}:({id: 1})   // not current ASUN

Write key-value collections as entry lists:

asun
{attrs@[{key@str, value@str}]}:([(lang, zig), (tier, prod)])

Short Grammar Summary

text
single   = schema ":" tuple
slice    = "[" schema "]" ":" rows
schema   = "{" fields "}"
field    = name ["@" type]
type     = "int" | "float" | "str" | "bool" | schema | "[" type "]"
rows     = tuple ("," tuple)*
tuple    = "(" values ")"
values   = value ("," value)*
value    = scalar | tuple | "[" values "]" | ""

See the full Syntax Reference for string, escaping, whitespace, and comment rules.

Released under the MIT License.