# Spread nested fields into columns

Shape / columns

A variant of [Parse nested values](https://meridian.online/operations/parse-nested-values).

Lift every field of a struct or object column into its own top-level column, one row still per row.

Page: <https://meridian.online/operations/parse-nested-values/spread-nested-fields-into-columns>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

spread the fields of a struct into top-level columns, one row per row

It reads the `orders` table the proofs share. Create it first:

```sql
CREATE TABLE orders AS SELECT * FROM (VALUES
  (1,  'Alice Ng',      'north', DATE '2026-01-03', 120.00, 'widget', 'a|b',   '{"channel":"web","items":[1,2]}'),
  (2,  'alice ng',      'north', DATE '2026-01-05',  80.50, 'gadget', 'b',     '{"channel":"shop","items":[3]}'),
  (3,  'Bob  Okafor',   'south', DATE '2026-01-05', 300.00, 'widget', 'a|c',   '{"channel":"web","items":[4,5,6]}'),
  (4,  'Carla Díaz',    'east',  DATE '2026-01-09',  NULL,  'gizmo',  NULL,    '{"channel":"web","items":[]}'),
  (5,  'Bob Okafor',    'south', DATE '2026-01-12',  45.25, 'gadget', 'c',     '{"channel":"phone","items":[7]}'),
  (6,  'Dev Patel',     'west',  DATE '2026-01-12', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (7,  'Carla Diaz',    'east',  DATE '2026-01-20',  99.99, 'gizmo',  'b|c',   '{"channel":"shop","items":[10]}'),
  (8,  'Dev Patel',     'west',  DATE '2026-02-02', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (9,  'Eve Larsen',    NULL,    DATE '2026-02-03',  15.00, 'gadget', NULL,    '{"channel":"web","items":[11]}'),
  (10, 'Alice Ng',      'north', DATE '2026-02-10', 220.00, 'gizmo',  'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);
```

Then run the statement:

```sql
CREATE TEMP TABLE raw AS
SELECT order_id, meta FROM orders UNION ALL SELECT 11, NULL;
CREATE TEMP TABLE result AS
SELECT order_id, s.* FROM (SELECT order_id, from_json(meta, '{"channel":"VARCHAR","items":["INTEGER"]}') AS s FROM raw);
SELECT * FROM result ORDER BY order_id;
DESCRIBE result;
SELECT CASE WHEN ((SELECT list(column_name) FROM (DESCRIBE result)) = ['order_id', 'channel', 'items'] AND (SELECT count(*) FROM result) = 11 AND (SELECT items FROM result WHERE order_id = 3) = [4, 5, 6] AND (SELECT count(*) FROM result WHERE order_id = 11 AND channel IS NULL AND items IS NULL) = 1) THEN 'as expected' ELSE error('the struct was not spread into a channel column and an items column with one row per row, or a missing struct lost its row') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

- Alteryx Designer: [`XML Parse`](https://help.alteryx.com/current/en/designer/tools/parse/xml-parse-tool.html) (read 2026-09-27)
- Apache DataFusion: [`unnest (struct)`](https://datafusion.apache.org/user-guide/sql/special_functions.html) (read 2026-09-27)
- Duckle: [`Flatten`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- AWS Glue: [`Flatten`](https://docs.aws.amazon.com/glue/latest/dg/transforms-flatten.html) (read 2026-09-27)
- AWS Glue: [`Simplify_ddb_json`](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-crawler-pyspark-transforms-simplify-ddb-json.html) (read 2026-09-27)
- AWS Glue: [`UnnestFrame`](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-crawler-pyspark-transforms-UnnestFrame.html) (read 2026-09-27)
- AWS Glue: [`unnest_ddb_json`](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-crawler-pyspark-extensions-dynamic-frame.html) (read 2026-09-27)
- KNIME Analytics Platform: [`JSON to Table`](https://api.hub.knime.com/nodes/*2xUDt4Z24aku4wiS?details=full) (read 2026-09-27)
- Apache NiFi: [`FlattenJson`](https://nifi.apache.org/components/org.apache.nifi.processors.standard.FlattenJson/) (read 2026-09-27)
- Polars: [`DataFrame.unnest`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- Power Query M: [`Table.ExpandRecordColumn`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#transformation) (read 2026-09-27)
- Talend: [`tExtractDynamicFields`](https://help.qlik.com/talend/en-US/components/8.0/processing/processing-component) (read 2026-09-27)
- Trifacta: [`Unnest Transform`](https://help.alteryx.com/aac/en/trifacta-classic/wrangle-language/language-appendices/transforms.html) (read 2026-09-27)
- Trifacta: [`Unnest elements`](https://help.alteryx.com/aac/en/trifacta-classic/reference/transformation-reference.html) (read 2026-09-27)
- VisiData: [`contract-col`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/expand_cols.py#L191) (read 2026-09-23)
- VisiData: [`contract-col-depth`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/expand_cols.py#L193) (read 2026-09-23)
- VisiData: [`contract-cols`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/expand_cols.py#L192) (read 2026-09-23)
- VisiData: [`contract-cols-depth`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/expand_cols.py#L194) (read 2026-09-23)
- VisiData: [`expand-col`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/expand_cols.py#L186) (read 2026-09-23)
- VisiData: [`expand-col-depth`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/expand_cols.py#L188) (read 2026-09-23)
- VisiData: [`expand-cols`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/expand_cols.py#L187) (read 2026-09-23)
- VisiData: [`expand-cols-depth`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/expand_cols.py#L189) (read 2026-09-23)
