I am having a table in my database in which there’s a field that holds data in a json format. How can I query records that have/don’t have a specific key-value pair in their json?
Something like this in pseudo code
SELECT * FROM `foo_db`.`foo_table`
WHERE `foo_field` IN_JSON exists('bar_key') // or IN_JSON !exists('bar_key')
3
Answers
None of the solutions proposed worked for me, so I had to do a lot of searching, but in the end I found something that worked for me, so posting it here
You could try JSON_SEARCH if you are looking for any string within the Json
You could use
JSON_CONTAINS
function.This function takes two arguments – the JSON document to search and the key-value to look for.