# Read each JSON object as one value

Acquire / file

A variant of [Read a JSON file](https://meridian.online/operations/read-a-json-file).

Read the file without unpacking it, giving one JSON value per object or document for later parsing.

Page: <https://meridian.online/operations/read-a-json-file/read-each-json-object-as-one-value>

## Status

Runs as a SQL step.

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

## The DuckDB step

read each JSON object and each document as one value

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 WHERE order_id <= 3) TO '<your_scratch_dir>/objects.ndjson' (FORMAT json);
COPY (SELECT order_id, customer, amount FROM orders WHERE order_id <= 3) TO '<your_scratch_dir>/objects_array.json' (FORMAT json, ARRAY true);
CREATE TEMP TABLE per_line AS SELECT json FROM read_json_objects('<your_scratch_dir>/objects.ndjson');
CREATE TEMP TABLE per_element AS SELECT json FROM read_json_objects('<your_scratch_dir>/objects_array.json', format = 'array');
CREATE TEMP TABLE per_document AS SELECT json FROM read_json_objects('<your_scratch_dir>/objects_array.json', format = 'unstructured');
SELECT * FROM per_line; SELECT * FROM per_element; SELECT * FROM per_document;
SELECT CASE WHEN ((SELECT list(column_name) FROM (DESCRIBE per_line)) = ['json'] AND (SELECT any_value(column_type) FROM (DESCRIBE per_line)) = 'JSON' AND (SELECT count(*) FROM per_line) = 3 AND (SELECT count(*) FROM per_element) = 3 AND (SELECT count(*) FROM per_document) = 1 AND (SELECT json_extract_string(json, '$.customer') FROM per_line WHERE json_extract(json, '$.order_id') = 3) = 'Bob  Okafor' AND (SELECT json_array_length(json) FROM per_document) = 3) THEN 'as expected' ELSE error('the objects were not read as one JSON column of 3 values, nor the array file as 3 elements or as 1 document') 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 `objects.ndjson` and `objects_array.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 95.7% of 324 rows (variant, version 3).

- DuckDB: `read_json_objects` (read 2026-09-27)
- DuckDB: `read_json_objects_auto` (read 2026-09-27)
- DuckDB: `read_ndjson_objects` (read 2026-09-27)
- KNIME Analytics Platform: [`JSON Reader`](https://api.hub.knime.com/nodes/*MJ89ZgBFq7ZpdhvG?details=full) (read 2026-09-27)
- Power Query M: [`Json.Document`](https://learn.microsoft.com/en-us/powerquery-m/accessing-data-functions) (read 2026-09-27)
