SQLite json_array() Function

The SQLite json_array() function evaluates all the values ​​in the parameters list and returns a JSON array containing all the parameters.

Syntax

Here is the syntax of the SQLite json_array() function:

json_array(value1[, value2[, ...]])

Parameters

value1[, value2[, ...]]

Required. Some values, they will be put in the result JSON array.

Return value

The SQLite json_array() function returns a JSON array that contains all the parameters in the parameters list.

There may be some conversions happening here:

  • TRUE is converted to 1
  • FALSE is converted to 0
  • NULL is converted to null

Examples

The following example illustrates the basic usage of the SQLite json_array() function:

SELECT json_array(123, 'abc', NULL, TRUE, FALSE);
json_array(123, 'abc', NULL, TRUE, FALSE)
-----------------------------------------
[123,"abc",null,1,0]

Let’s look at a few other examples:

SELECT
    json_array(1,2,'3',4),
    json_array('[1,2]'),
    json_array(json_array(1,2)),
    json_array(1,null,'3','[4,5]','{"six":7.7}'),
    json_array(1,null,'3',json('[4,5]'));
                       json_array(1,2,'3',4) = [1,2,"3",4]
                         json_array('[1,2]') = ["[1,2]"]
                 json_array(json_array(1,2)) = [[1,2]]
json_array(1,null,'3','[4,5]','{"six":7.7}') = [1,null,"3","[4,5]","{\"six\":7.7}"]
        json_array(1,null,'3',json('[4,5]')) = [1,null,"3",[4,5]]

Here the json() function is used to convert a json text to a json value.