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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With