SQLite 3 reference · JSON Functions
SQLite JSON_SET() Function
Return JSON with values set at paths, creating or overwriting them. json_insert() and json_replace() are stricter.
SQLite 3 Since 3.9.0
Syntax
json_set(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 new value. |
Return value
The modified JSON text.
Examples
SELECT json_set('{"name":"Ada"}', '$.name', 'Grace', '$.age', 36) AS updated;
Output
updated
{"name":"Grace","age":36}SELECT json_set('{"tags":["a"]}', '$.tags[#]', 'b') AS appended;
Output
appended
{"tags":["a","b"]}Version history
| Version | Change |
|---|---|
| SQLite 3.9.0 | Added |
| SQLite 3.38.0 | Built in by default; earlier versions needed the JSON1 extension. |
In other languages
JSONB_SET()· PostgreSQL
Related
JSON_INSERT()· Return JSON with values added at paths that don't exist yet. Existing values are left unchanged.JSON_REPLACE()· Return JSON with values replaced at paths that already exist. Missing paths are not created.JSON_REMOVE()· Return JSON with the elements at the given paths removed. Paths that don't exist are ignored.JSON_PATCH()· Merge one JSON object into another using RFC 7396 MergePatch: keys are added or replaced, null removes a key.- SQL String Functions · tutorial