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
Syntax
json_replace(json, path, value, ...)
Parameters
| Parameter | Description |
|---|---|
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
SELECT json_replace('{"name":"Ada"}', '$.name', 'Grace', '$.city', 'London') AS result;
Output
result
{"name":"Grace"}SELECT json_replace('{"stock":5}', '$.stock', 0) AS sold_out;
Output
sold_out
{"stock":0}Version history
| Version | Change |
|---|---|
| SQLite 3.9.0 | Added |
| SQLite 3.38.0 | Built in by default; earlier versions needed the JSON1 extension. |
Related
JSON_SET()· Return JSON with values set at paths, creating or overwriting them. json_insert() and json_replace() are stricter.JSON_INSERT()· Return JSON with values added at paths that don't exist yet. Existing values are left unchanged.- SQL String Functions · tutorial