SQLite 3 reference · JSON Functions

SQLite JSON_EACH() Function

A table-valued function that returns one row per element of a JSON array or object, with key, value and type columns.

SQLite 3 Since 3.9.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

SELECT ... FROM json_each(json, path)

Parameters

ParameterDescription
json JSON text (or JSONB).
path optional Walk the array or object at this path.

Return value

Rows with key, value, type, atom, id, parent, fullkey and path columns.

Examples

Walk an objectTry it yourself
SELECT key, value, type
FROM json_each('{"a":1,"b":"two","c":[3]}');

Output

key | value | type
a | 1 | integer
b | two | text
c | [3] | array
Count array values across rowsTry it yourself
WITH posts(id, tags) AS (VALUES (1, '["sql","json"]'), (2, '["sql"]'))
SELECT tag.value AS tag, count(*) AS posts
FROM posts, json_each(posts.tags) AS tag
GROUP BY tag.value;

Output

tag | posts
json | 1
sql | 2

Version history

VersionChange
SQLite 3.9.0Added
SQLite 3.38.0Built in by default; earlier versions needed the JSON1 extension.

In other languages

Was this page helpful?