SQLite 3 reference · JSON Functions

SQLite JSON_REPLACE() Function

Return JSON with values replaced at paths that already exist. Missing paths are not created.

SQLite 3 Since 3.9.0

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

Syntax

json_replace(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 replacement.

Return value

The modified JSON text.

Examples

Replace only existing keysTry it yourself
SELECT json_replace('{"name":"Ada"}', '$.name', 'Grace', '$.city', 'London') AS result;

Output

result
{"name":"Grace"}
Update a valueTry it yourself
SELECT json_replace('{"stock":5}', '$.stock', 0) AS sold_out;

Output

sold_out
{"stock":0}

Version history

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

Was this page helpful?