# Write a nested value as text

Shape / columns

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

Turn a struct, list or JSON value back into a JSON text string.

Page: <https://meridian.online/operations/parse-nested-values/write-nested-value-as-text>

## Status

Runs as a SQL step.

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

## The DuckDB step

write a struct, a list and a JSON value as JSON text

```sql
CREATE TEMP TABLE nested AS SELECT * FROM (VALUES
  (1, {'channel': 'web', 'n': 2},   [1, 2, 3],         '{"a": [1,  2]}'::JSON),
  (2, {'channel': NULL,  'n': 0},   []::INTEGER[],     '{"a": null}'::JSON),
  (3, NULL,                         NULL,              NULL)
) t(id, s, l, j);
CREATE TEMP TABLE result AS
SELECT id, to_json(s)::VARCHAR AS s_text, to_json(l)::VARCHAR AS l_text, to_json(j)::VARCHAR AS j_text FROM nested;
SELECT * FROM result ORDER BY id;
SELECT CASE WHEN ((SELECT [s_text, l_text, j_text] FROM result WHERE id = 1) = ['{"channel":"web","n":2}', '[1,2,3]', '{"a":[1,2]}'] AND (SELECT [s_text, l_text, j_text] FROM result WHERE id = 2) = ['{"channel":null,"n":0}', '[]', '{"a":null}'] AND (SELECT count(*) FROM result WHERE id = 3 AND s_text IS NULL AND l_text IS NULL AND j_text IS NULL) = 1) THEN 'as expected' ELSE error('the struct, the list and the JSON value were not written as JSON text, or a missing value did not stay missing') END AS verdict;
```

The statement builds its own data.

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).

- Azure Data Factory: [`Stringify`](https://learn.microsoft.com/en-us/azure/data-factory/data-flow-stringify) (read 2026-09-27)
- Duckle: [`Stringify JSON`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- Power Query M: [`Json.FromValue`](https://learn.microsoft.com/en-us/powerquery-m/accessing-data-functions) (read 2026-09-27)
