Validate data is in JSON format for MariaDB or MySQL

Check the data is in JSON format for MariaDB or MySQL

JSON_VALID() is the function that will let us know that the column value has valid JSON data by returning 1 other wise return 0 for non-JSON format data.

--Check the JSON data
SELECT JSON_VALID('{"id": "1"}') AS Result;
Result:
-------
1

--Check the NON-JSON data
SELECT JSON_VALID('abc') AS Result;
Result:
------
0

Validate that the data in the column of the table is in JSON format

-- Check the bad data which not in json format
select datajson from customerdoc where JSON_VALID(datajson) = 0
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.