SQLite 3 reference · JSON Functions

SQLite JSON_INSERT() Function

Return JSON with values added at paths that don't exist yet. Existing values are left unchanged.

SQLite 3 Since 3.9.0

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

Syntax

json_insert(json, path, value, ...)

Parameters

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

Return value

The modified JSON text.

Examples

Add only new keysTry it yourself
SELECT json_insert('{"name":"Ada"}', '$.name', 'Grace', '$.city', 'London') AS result;

Output

result
{"name":"Ada","city":"London"}
Append to an arrayTry it yourself
SELECT json_insert('[1,2]', '$[#]', 3) AS appended;

Output

appended
[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?