Skip to content
Astera Technology

Why does an empty-lines report treat an object as an empty array?

Check JSON kind before interpreting array length.

Download complete case notes and answer keys ↓

Prepare the report input

Original report needs an actual empty lines array. json_array_length returns zero for a located non-array too, so length zero alone admits an object. Require json_type=array as well as zero length. Payload syntax is valid but shape may differ.

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: documents
idpayload
A{"lines":[]}
B{"lines":{}}
C{"lines":[1]}
Download editable CSV ↓
Complete CREATE and INSERT fixture
CREATE TABLE documents(id TEXT PRIMARY KEY,payload TEXT NOT NULL CHECK(json_valid(payload))); INSERT INTO documents VALUES('A','{"lines":[]}'),('B','{"lines":{}}'),('C','{"lines":[1]}');

Compare misleading and corrected results

Misleading SELECT: reproduce the defect
SELECT id FROM documents WHERE json_array_length(payload,'$.lines')=0 ORDER BY id;
Literal misleading result
id
A
B
Download editable CSV ↓
Corrected SELECT
SELECT id FROM documents WHERE json_type(payload,'$.lines')='array' AND json_array_length(payload,'$.lines')=0 ORDER BY id;
Literal corrected result
id
A
Download editable CSV ↓

A has [], B has {} and C has [1]. Only A is an empty array. B is a different shape requiring separate review, not a zero-line document.

Check a fresh boundary case

Add lines:null. It remains outside the empty-array result.

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 documents VALUES('D','{"lines":null}');
SELECT id FROM documents WHERE json_type(payload,'$.lines')='array' AND json_array_length(payload,'$.lines')=0 ORDER BY id;
Literal boundary result
id
A
Download editable CSV ↓

Can zero returned length alone certify an empty array?

Show the worked answer

No. A type check distinguishes the actual empty array from object or null values.

Related resources