Predictive Hacks

How to search JSON for a string in Prostgres

This is useful when we are dealing with big nested JSON’s in our data and we just want to look for rows that has a specific string as key or value. A smart solution is to convert the JSON into a string and then look if the value we want to find is contained in that string.

SELECT * FROM  
(SELECT json_colum#>>'{}' as converted_json FROM table ) a 
WHERE a.converted_json like '%value%'

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Python

Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.