SQLite 3 reference · JSON Functions
SQLite JSON_TYPE() Function
Return the JSON type of a value or path: 'null', 'true', 'false', 'integer', 'real', 'text', 'array' or 'object'.
SQLite 3 Since 3.9.0
Syntax
json_type(json, path)
Parameters
| Parameter | Description |
|---|---|
json |
JSON text (or JSONB). |
path optional |
The element to inspect. |
Return value
Text, or NULL if the path doesn't exist.
Examples
SELECT json_type('{"a":[1,2]}') AS root, json_type('{"a":[1,2]}', '$.a') AS a, json_type('{"a":[1,2]}', '$.a[0]') AS first;
Output
root | a | first object | array | integer
SELECT json_type('{"ok":true}', '$.ok') AS ok, json_type('{"ok":true}', '$.missing') AS missing;
Output
ok | missing true | NULL
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_TYPEOF()· PostgreSQL
Related
JSON_VALID()· Return 1 if a string is well-formed JSON and 0 if it isn't. Use it in CHECK constraints or before parsing.JSON_EXTRACT()· Read one or more values from JSON by path. JSON objects and arrays come back as text; numbers and strings as SQL values.- SQL String Functions · tutorial