# Write a JSON file

Publish / file

write JSON, NDJSON

Page: <https://meridian.online/operations/write-a-json-file>

## Status

Runs as a SQL step.

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

## The DuckDB step

write a JSON array

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
COPY (SELECT order_id, customer, amount FROM orders) TO '<your_scratch_dir>/out.json' (FORMAT json, ARRAY true);
CREATE TEMP TABLE result AS
SELECT count(*) AS n, sum(amount) AS total, (SELECT left(content, 1) FROM read_text('<your_scratch_dir>/out.json')) AS opens_with FROM read_json('<your_scratch_dir>/out.json');
SELECT * FROM result;
SELECT CASE WHEN ((SELECT n = 10 AND total = 1900.74 AND opens_with = '[' FROM result)) THEN 'as expected' ELSE error('the file is not a JSON array of 10 rows') END AS verdict;
```

Replace `<your_scratch_dir>` with a directory of your own that you can write to before running the statement.

The statement writes `out.json` itself, in `<your_scratch_dir>`.

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 86.2% of 312 rows (exact class, version 2).

- Azure Data Factory: [`JSON format (sink)`](https://learn.microsoft.com/en-us/azure/data-factory/format-json) (read 2026-09-27)
- Apache DataFusion: [`Data Insert: JSON`](https://datafusion.apache.org/user-guide/features.html) (read 2026-09-27)
- Apache DataFusion: [`write_json`](https://docs.rs/datafusion/latest/datafusion/dataframe/struct.DataFrame.html) (read 2026-09-27)
- Duckle: [`JSON`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- Duckle: [`JSONL / NDJSON`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- AWS Glue: [`JSON (write)`](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-format-json-home.html) (read 2026-09-27)
- Apache Hop: [`Enhanced JSON output`](https://hop.apache.org/manual/latest/pipeline/transforms/enhancedjsonoutput.html) (read 2026-09-27)
- Apache Hop: [`JSON Output`](https://hop.apache.org/manual/latest/pipeline/transforms/jsonoutput.html) (read 2026-09-27)
- KNIME Analytics Platform: [`JSON Row Combiner and Writer`](https://api.hub.knime.com/nodes/*xXV75_xSTeUq_uHc?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`JSON Writer`](https://api.hub.knime.com/nodes/*NGuc4eckZ730R9C2?details=full) (read 2026-09-27)
- Apache NiFi: [`JsonRecordSetWriter`](https://nifi.apache.org/components/org.apache.nifi.json.JsonRecordSetWriter/) (read 2026-09-27)
- Pentaho Data Integration: [`JSON output`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Polars: [`DataFrame.write_json`](https://docs.pola.rs/api/python/stable/reference/io.html) (read 2026-09-27)
- Polars: [`DataFrame.write_ndjson`](https://docs.pola.rs/api/python/stable/reference/io.html) (read 2026-09-27)
- Polars: [`LazyFrame.sink_ndjson`](https://docs.pola.rs/api/python/stable/reference/io.html) (read 2026-09-27)
- Apache SeaTunnel: [`CDC Compatible Debezium-json`](https://seatunnel.apache.org/docs/2.3.13/connectors/formats/cdc-compatible-debezium-json) (read 2026-09-27)
- Talend: [`tFileOutputJSON`](https://help.qlik.com/talend/en-US/components/8.0/json/json-component) (read 2026-09-27)
- VisiData: [`json (saver)`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/loaders/json.py#L136) (read 2026-09-23)
- VisiData: [`jsonl (saver)`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/loaders/json.py#L187) (read 2026-09-23)
- VisiData: [`jsonla (saver)`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/loaders/jsonla.py#L74) (read 2026-09-23)
