Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I ignore invalid JSON when using json_parse with PrestoDB?

Tags:

json

presto

I am fairly new to Presto, and am trying to parse a bunch of records containing JSON data. It appears that some of the data is invalid, which causes Presto to abort the query during the call to json_parse. Is it possible to somehow return NULL instead of throwing an error in this case?

It seems like previously you could use try_cast(value as json), but that was removed in favor of json_parse. Is there any sort of configuration I can change to resolve this, or do I need to resort to creating a custom SerDe?

like image 220
BenV Avatar asked Oct 14 '25 23:10

BenV


1 Answers

It looks like json_extract(data, '$') will return NULL for invalid JSON:

presto:default> select json_extract('{', '$');
 _col0 
-------
 NULL  
(1 row)
like image 164
BenV Avatar answered Oct 17 '25 13:10

BenV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!