Skip to content
Astera Technology

Why does a JSON object export contain strings instead of objects?

Mark validated object text as a JSON value at aggregation.

Download complete case notes and answer keys ↓

Prepare the report input

Original table stores valid object fragments as TEXT. Passing ordinary text to json_group_array quotes each fragment as a JSON string. json(fragment) supplies a JSON value, producing an array of objects in id order.

Every record and report rule below is original and fictional. Reproduce the setup in a fresh SQLite test database; input previews include every table in this small fixture.

Synthetic input: fragments
idfragment
1{"name":"A"}
2{"name":"B"}
Download editable CSV ↓
Complete CREATE and INSERT fixture
CREATE TABLE fragments(id INTEGER PRIMARY KEY,fragment TEXT NOT NULL CHECK(json_valid(fragment) AND json_type(fragment)='object')); INSERT INTO fragments VALUES(1,'{"name":"A"}'),(2,'{"name":"B"}');

Compare misleading and corrected results

Misleading SELECT: reproduce the defect
SELECT json_group_array(fragment ORDER BY id) AS objects FROM fragments;
Literal misleading result
objects
["{\"name\":\"A\"}","{\"name\":\"B\"}"]
Download editable CSV ↓
Corrected SELECT
SELECT json_group_array(json(fragment) ORDER BY id) AS objects FROM fragments;
Literal corrected result
objects
[{"name":"A"},{"name":"B"}]
Download editable CSV ↓

The bad array needs another parse per element; the corrected array already contains objects A and B. Schema checks require each input fragment to be a valid object.

Check a fresh boundary case

Add {} as a third object. The export preserves the empty object as an element.

Recreate the original setup in another fresh database, then apply the change and corrected query below. For an empty result, the table displays a labelled empty-result marker rather than a data record.

Boundary change and corrected query
INSERT INTO fragments VALUES(3,'{}');
SELECT json_group_array(json(fragment) ORDER BY id) AS objects FROM fragments;
Literal boundary result
objects
[{"name":"A"},{"name":"B"},{}]
Download editable CSV ↓

Is an empty object lost in the corrected export?

Show the worked answer

No. The boundary array contains A, B and {}, all as objects rather than quoted object strings.

Related resources

System integration services →