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 a JSON field
SELECT json_extract(payload, '$.type') AS event_type FROM events;

# Read one property from a JSON document.

Use JSON operators
SELECT payload -> '$.type' AS raw_json,
       payload ->> '$.type' AS text_value
FROM events;

# Read a JSON path with operator syntax.

Validate JSON text
SELECT json_valid(payload) FROM events;

# Check whether a string contains valid JSON.

Inspect the JSON type at a path
SELECT json_type(payload, '$.user') FROM events;

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

## Update and expand JSON
Update or insert a JSON field
UPDATE settings
SET config = json_set(config, '$.theme', 'dark')
WHERE user_id = 1;

# Patch a document with json_set().

Remove a JSON key
UPDATE settings
SET config = json_remove(config, '$.deprecated_flag')
WHERE user_id = 1;

# Delete one path from a document.

Expand an array with json_each
SELECT value AS tag
FROM json_each('["sqlite", "json", "fts"]');

# Turn array elements into result rows.

Join against JSON array values in a column
SELECT a.id, je.value AS role
FROM accounts a,
     json_each(a.roles_json) AS je
WHERE je.value = 'admin';

# Search inside per-row arrays.

Recommended next

No recommendations yet.