Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate json format in prestoDB

Tags:

json

presto

We use presto JSON capabilities quit heavily and on thing the is missing for us is to be able to null when JSON is not a valid on this way SQL statement that use JSON functions will not break if there is a problem with the JSON format.

Initially I thought it can be done with some combination of JSON_PARSE and NULLIF but couldn't manage to pull this of.. is there a way to do make this kind of validation?

Thanks

like image 731
Lior Baber Avatar asked Sep 02 '25 04:09

Lior Baber


1 Answers

You can use the try function to prevent the json functions from failing the query. For example, SELECT try(json_parse('bad json')) will return null instead of failing the query.

like image 149
Dain Sundstrom Avatar answered Sep 04 '25 19:09

Dain Sundstrom