Skip to content
Astera Technology

Why does numeric JSON 1 pass a true-only flag report?

Keep the JSON origin type when a Boolean literal is required.

Download complete case notes and answer keys ↓

Prepare the report input

Original queue requires literal JSON true in ready. Extraction turns that Boolean into SQL integer 1, the same scalar value as numeric JSON 1. Testing the returned JSON type name “true” checks the original kind instead. Here ready is an original local Boolean report flag.

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{"ready":true}
B{"ready":1}
C{"ready":false}
D{"ready":"true"}
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','{"ready":true}'),('B','{"ready":1}'),('C','{"ready":false}'),('D','{"ready":"true"}');

Compare misleading and corrected results

Misleading SELECT: reproduce the defect
SELECT id FROM documents WHERE json_extract(payload,'$.ready')=1 ORDER BY id;
Literal misleading result
id
A
B
Download editable CSV ↓
Corrected SELECT
SELECT id FROM documents WHERE json_type(payload,'$.ready')='true' ORDER BY id;
Literal corrected result
id
A
Download editable CSV ↓

The bad result includes A=true and B=1. Only A qualifies; false and text true remain different values.

Check a fresh boundary case

Add explicit JSON null. It is not true and does not join the list.

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('E','{"ready":null}');
SELECT id FROM documents WHERE json_type(payload,'$.ready')='true' ORDER BY id;
Literal boundary result
id
A
Download editable CSV ↓

Why must B’s numeric one be excluded?

Show the worked answer

Its origin type is integer, not true. Equal extracted scalar value does not satisfy the supplied Boolean-kind rule.

Related resources