SQLite JSON_EXTRACT() Function
Example
Return the age:
SELECT JSON_EXTRACT(
'{"name": "Emil", "age": 30}', '$.age');
Try it Yourself »
Definition and Usage
The JSON_EXTRACT() function returns a value from a JSON text. With one path, it returns an SQL value, like a text or a number. With more than one path, it returns a JSON array with the values.
SQLite 3.38.0 and later also has two operators for this. ->> returns an SQL value, like JSON_EXTRACT(). -> returns the value as JSON.
Note: Read more about JSON in the SQLite JSON chapter.
Syntax
JSON_EXTRACT(json, path, ...)
json ->> path
json -> path
Parameter Values
| Parameter | Description |
|---|---|
| json | Required. The JSON text |
| path | Required. A JSON path, like '$.name' for a value in an object, '$[0]' for the first item in an array, or '$.a.b' for a value inside another object |
Technical Details
| Return type: | Same as the value |
|---|
More Examples
Example
Use the ->> and -> operators:
SELECT '{"name": "Emil"}' ->> '$.name',
'{"name": "Emil"}' -> '$.name';
Try it Yourself »
Example
Return the last item of an array:
SELECT JSON_EXTRACT('[10, 20, 30]', '$[#-1]');
Try it Yourself »