{
  "cases": [
    {
      "case": "bare json_extract, no other filter",
      "clean": "ok: 401 rows",
      "plan": "SCAN things",
      "sql": "SELECT id FROM things WHERE json_extract(state_json, '$.carried_by') = 'av1'",
      "survived": false,
      "with_bad_row": "OperationalError: malformed JSON"
    },
    {
      "case": "the ->> operator instead",
      "clean": "ok: 401 rows",
      "plan": "SCAN things",
      "sql": "SELECT id FROM things WHERE state_json ->> '$.carried_by' = 'av1'",
      "survived": false,
      "with_bad_row": "OperationalError: malformed JSON"
    },
    {
      "case": "a second predicate that excludes the bad row",
      "clean": "ok: 1 rows",
      "plan": "SCAN things",
      "sql": "SELECT id FROM things WHERE x = 100 AND json_extract(state_json, '$.carried_by') = 'av1'",
      "survived": true,
      "with_bad_row": "ok: 1 rows"
    },
    {
      "case": "the same, with an index on x",
      "clean": "ok: 1 rows",
      "plan": "SEARCH things USING INDEX ix (x=?)",
      "sql": "SELECT id FROM things WHERE x = 100 AND json_extract(state_json, '$.carried_by') = 'av1'",
      "survived": true,
      "with_bad_row": "ok: 1 rows"
    },
    {
      "case": "json_valid() guard written first",
      "clean": "ok: 401 rows",
      "plan": "SCAN things",
      "sql": "SELECT id FROM things WHERE json_valid(state_json) AND json_extract(state_json, '$.carried_by') = 'av1'",
      "survived": true,
      "with_bad_row": "ok: 401 rows"
    },
    {
      "case": "json_valid() guard, and the bad row is also excluded by x",
      "clean": "ok: 1 rows",
      "plan": "SCAN things",
      "sql": "SELECT id FROM things WHERE json_valid(state_json) AND x = 100 AND json_extract(state_json, '$.carried_by') = 'av1'",
      "survived": true,
      "with_bad_row": "ok: 1 rows"
    },
    {
      "case": "CASE WHEN json_valid(...) THEN json_extract(...) END",
      "clean": "ok: 401 rows",
      "plan": "SCAN things",
      "sql": "SELECT id FROM things WHERE CASE WHEN json_valid(state_json) THEN json_extract(state_json, '$.carried_by') END = 'av1'",
      "survived": true,
      "with_bad_row": "ok: 401 rows"
    },
    {
      "case": "a CHECK constraint on the column",
      "clean": "ok: 401 rows",
      "plan": "SCAN things",
      "sql": "SELECT id FROM things WHERE json_extract(state_json, '$.carried_by') = 'av1'",
      "survived": true,
      "with_bad_row": "refused at write: CHECK constraint failed: state_json IS NULL OR json_valid(state_json)"
    }
  ],
  "sqlite_version": "3.45.1"
}