IS_VALID_JSON_ARRAY function
The IS_VALID_JSON_ARRAY function validates a JSON array. The function returns Boolean
true
(t
) if the array is properly formed JSON or
false
(f
) if the array is malformed. To validate a JSON
string, use IS_VALID_JSON function
For more information, see JSON functions.
Syntax
is_valid_json_array('
json_array
')
Arguments
- json_array
-
A string or expression that evaluates to a JSON array.
Return type
BOOLEAN
Example
The following example creates a table and inserts JSON strings for testing.
create table test_json_arrays(id int identity(0,1), json_arrays varchar); -- Insert valid JSON array strings -- insert into test_json_arrays(json_arrays) values('[]'), ('["a","b"]'), ('["a",["b",1,["c",2,3,null]]]'); -- Insert invalid JSON array strings -- insert into test_json_arrays(json_arrays) values ('{"a":1}'), ('a'), ('[1,2,]');
The following example validates the strings in the preceding example.
select json_arrays, is_valid_json_array(json_arrays) from test_json_arrays order by id; json_arrays | is_valid_json_array -----------------------------+-------------------- [] | true ["a","b"] | true ["a",["b",1,["c",2,3,null]]] | true {"a":1} | false a | false [1,2,] | false