0

It is stored in MySQL DB in the form below.

"config" is a JSON type and it's an array of objects.

I want to query the data that has "config" containing the object "type" is "download".

(i.e. data with "id=test2" and "id=test3" in the example below)

I'm having a lot of trouble doing queries that include JSON type.

"id":"test1", "config":[{"type": "get", "request": {}}]
"id":"test2", "config":[{"type": "set", "request": {}}, {"type": "download", "request": {}}]
"id":"test3", "config":[{"type": "download", "request": {}}, {"type": "reset", "request": {}}]
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
justin
  • 13
  • 1
  • 3

1 Answers1

0

You can do this with json_extract() and json_contains():

select t.*
from mytable t
where json_contains(json_extract(config, '$[*].type'), '"download"')
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
GMB
  • 216,147
  • 25
  • 84
  • 135