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.
| id | payload |
|---|---|
| A | {"ready":true} |
| B | {"ready":1} |
| C | {"ready":false} |
| D | {"ready":"true"} |
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
SELECT id FROM documents WHERE json_extract(payload,'$.ready')=1 ORDER BY id;| id |
|---|
| A |
| B |
SELECT id FROM documents WHERE json_type(payload,'$.ready')='true' ORDER BY id;| id |
|---|
| A |
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.
INSERT INTO documents VALUES('E','{"ready":null}');
SELECT id FROM documents WHERE json_type(payload,'$.ready')='true' ORDER BY id;| id |
|---|
| A |
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.