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

IS_VALID_JSON Function

IS_VALID_JSON validates a JSON string. The function returns Boolean true (t) if the string is properly formed JSON or false (f) if the string is malformed. To validate a JSON array, use IS_VALID_JSON_ARRAY Function

For more information, see JSON Functions.

Syntax

Copy
is_valid_json('json_string')

Arguments

json_string

A string or expression that evaluates to a JSON string.

Return Type

BOOLEAN

Example

The following example creates a table and inserts JSON strings for testing.

Copy
create table test_json(id int identity(0,1), json_strings varchar); -- Insert valid JSON strings -- insert into test_json(json_strings) values ('{"a":2}'), ('{"a":{"b":{"c":1}}}'), ('{"a": [1,2,"b"]}'); -- Insert invalid JSON strings -- insert into test_json(json_strings)values ('{{}}'), ('{1:"a"}'), ('[1,2,3]');

The following example validates the strings in the preceding example.

Copy
select id, json_strings, is_valid_json(json_strings) from test_json order by id; id | json_strings | is_valid_json ---+---------------------+-------------- 0 | {"a":2} | true 2 | {"a":{"b":{"c":1}}} | true 4 | {"a": [1,2,"b"]} | true 6 | {{}} | false 8 | {1:"a"} | false 10 | [1,2,3] | false