Menu
Amazon Redshift
Database Developer Guide (API Version 2012-12-01)

IS_VALID_JSON_ARRAY Function

IS_VALID_JSON 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_ARRAY Function

For more information, see JSON Functions.

Syntax

Copy
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.

Copy
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.

Copy
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