SQLite 3 reference · JSON Functions

SQLite JSON_ARRAY_LENGTH() Function

Return the number of elements in a JSON array, optionally at a path. Non-arrays give 0.

SQLite 3 Since 3.9.0

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

Syntax

json_array_length(json, path)

Parameters

ParameterDescription
json JSON text (or JSONB).
path optional Where the array is.

Return value

An integer, or NULL if the path doesn't exist.

Examples

Count elementsTry it yourself
SELECT json_array_length('[1, 2, 3]') AS a,
       json_array_length('{"tags":["x","y"]}', '$.tags') AS b,
       json_array_length('{"x":1}') AS not_array;

Output

a | b | not_array
3 | 2 | 0
Per rowTry it yourself
WITH posts(tags) AS (VALUES ('["sql","json"]'), ('[]'))
SELECT tags, json_array_length(tags) AS n FROM posts;

Output

tags | n
["sql","json"] | 2
[] | 0

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?