SQLite 3 reference · JSON Functions

SQLite JSON_EXTRACT() Function

Read one or more values from JSON by path. JSON objects and arrays come back as text; numbers and strings as SQL values.

SQLite 3 Since 3.9.0

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

Syntax

json_extract(json, path, ...)

Parameters

ParameterDescription
json JSON text (or JSONB).
path A path such as '$.name', '$.items[0]' or '$.items[#-1]' (last element).

Return value

An SQL value, JSON text, or NULL when the path doesn't exist.

Examples

Read nested valuesTry it yourself
SELECT json_extract('{"user":{"name":"Ada","langs":["en","fr"]}}', '$.user.name') AS name,
       json_extract('{"user":{"name":"Ada","langs":["en","fr"]}}', '$.user.langs[1]') AS second_lang;

Output

name | second_lang
Ada | fr
Several paths return an arrayTry it yourself
SELECT json_extract('{"a":1,"b":[2,3]}', '$.a', '$.b') AS several;

Output

several
[1,[2,3]]

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?