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
Syntax
json_insert(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 value to add. |
Return value
The modified JSON text.
Examples
SELECT json_insert('{"name":"Ada"}', '$.name', 'Grace', '$.city', 'London') AS result;
Output
result
{"name":"Ada","city":"London"}SELECT json_insert('[1,2]', '$[#]', 3) AS appended;
Output
appended [1,2,3]
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_INSERT()· PostgreSQL
Related
JSON_SET()· Return JSON with values set at paths, creating or overwriting them. json_insert() and json_replace() are stricter.JSON_REPLACE()· Return JSON with values replaced at paths that already exist. Missing paths are not created.- SQL String Functions · tutorial