SELECT json_extract(payload, '$.type') AS event_type FROM events;A core pattern for event logs and flexible payload columns.
json_extract, json_set, json_each, JSON operators, generated columns, and practical JSON query/update patterns in SQLite.
Extract fields and project JSON into relational queries.
SELECT json_extract(payload, '$.type') AS event_type FROM events;A core pattern for event logs and flexible payload columns.
SELECT payload -> '$.type' AS raw_json,
payload ->> '$.type' AS text_value
FROM events;`->` returns JSON text while `->>` returns a scalar SQL value when appropriate.
SELECT json_valid(payload) FROM events;Useful before imports, migrations, or backfilling generated columns.
SELECT json_type(payload, '$.user') FROM events;Helpful when cleaning inconsistent payloads from multiple producers.
Patch documents and turn arrays into rows.
UPDATE settings
SET config = json_set(config, '$.theme', 'dark')
WHERE user_id = 1;A practical way to update JSON without replacing the whole document in app code.
UPDATE settings
SET config = json_remove(config, '$.deprecated_flag')
WHERE user_id = 1;Useful during schema cleanup or feature-flag retirement.
SELECT value AS tag
FROM json_each('["sqlite", "json", "fts"]');`json_each` is a table-valued function and belongs in the FROM clause.
SELECT a.id, je.value AS role
FROM accounts a,
json_each(a.roles_json) AS je
WHERE je.value = 'admin';Great for analytics and migrations, though highly queried JSON fields are often better normalized or indexed via generated columns.