SQLite json_type() Function
The SQLite json_type() function returns the type of a JSON value or the value of the specified path in JSON document.
Syntax
Here is the syntax of the SQLite json_type() function:
json_type(json_doc)
or
json_type(json_doc, path)
Parameters
json_doc-
Required. A JSON value.
path-
Optional. The path expression in
json_doc.
Return value
The json_type() function returns a string that represents the type of the given JSON value. The json_type() function will return one of the following values:
'object': JSON object'array': JSON array'text': JSON string'integer': JSON integer'real': JSON float'true': JSON valuetrue'false': JSON valuefalse'null': JSON valuenull
This function will return NULL if the parameter is NULL.
SQLite will give an error if the parameter is not a valid JSON document. You can use json_valid() verify JSON documents.
Examples
Here are some examples to show the usages of json_type().
Example 1: Get type of JSON values
SELECT
json_type('true'),
json_type('false'),
json_type('null'),
json_type('"abc"');
json_type('true') = true
json_type('false') = false
json_type('null') = null
json_type('"abc"') = textExample 2: Get type of JSON Numbers
SELECT
json_type('1'),
json_type('1.23');
json_type('1') = integer
json_type('1.23') = realExample 3: Get type of JSON Arrays
SELECT
json_type('[]'),
json_type('[1, 2]');
json_type('[]') = array
json_type('[1, 2]') = arrayExample 4: Get type of JSON Objects
SELECT
json_type('{}'),
json_type('{"x": 1}');
json_type('{}') = object
json_type('{"x": 1}') = objectExample 5: Get type of JSON value in a Path
SELECT json_type('{"x": 1}', '$.x');
json_type('{"x": 1}', '$.x') = integer