SQLite JSON Functions Cheatsheet

json_extract, json_set, json_each, JSON operators, generated columns, and practical JSON query/update patterns in SQLite.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Read JSON values

Extract fields and project JSON into relational queries.

Extract a JSON field

Read one property from a JSON document.

sqlANYsqlitejson_extract
sql
SELECT json_extract(payload, '$.type') AS event_type FROM events;

A core pattern for event logs and flexible payload columns.

Use JSON operators

Read a JSON path with operator syntax.

sqlANYsqlitejson operatorsarrow
sql
SELECT payload -> '$.type' AS raw_json,
       payload ->> '$.type' AS text_value
FROM events;

`->` returns JSON text while `->>` returns a scalar SQL value when appropriate.

Validate JSON text

Check whether a string contains valid JSON.

sqlANYsqlitejson_valid
sql
SELECT json_valid(payload) FROM events;

Useful before imports, migrations, or backfilling generated columns.

Inspect the JSON type at a path

See whether a value is text, array, object, number, and so on.

sqlANYsqlitejson_type
sql
SELECT json_type(payload, '$.user') FROM events;

Helpful when cleaning inconsistent payloads from multiple producers.

Update and expand JSON

Patch documents and turn arrays into rows.

Update or insert a JSON field

Patch a document with json_set().

sqlANYsqlitejson_setupdate
sql
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.

Remove a JSON key

Delete one path from a document.

sqlANYsqlitejson_remove
sql
UPDATE settings
SET config = json_remove(config, '$.deprecated_flag')
WHERE user_id = 1;

Useful during schema cleanup or feature-flag retirement.

Expand an array with json_each

Turn array elements into result rows.

sqlANYsqlitejson_eacharray
sql
SELECT value AS tag
FROM json_each('["sqlite", "json", "fts"]');

`json_each` is a table-valued function and belongs in the FROM clause.

Join against JSON array values in a column

Search inside per-row arrays.

sqlANYsqlitejson_eachjoin
sql
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.

Recommended next

No recommendations yet.