Check your JSON value. I copied your Value
to a JSON validator and it does not like single quotes. So if I run the following I get no results:
SET @mapJSON = "[{'id': 116298, 'name': 'Data Analysis', 'language': 'en'}, {'id': 5462, 'name': 'Visualization', 'language': '00'}]";
SELECT JSON_SEARCH(@mapJSON, "all", "name") as t WHERE JSON_VALID(@mapJSON)=1; -- no result returned
The other problem is that JSON_SEARCH will search on a value, so if you run the following SQL you will get ["$[0].name", "$[2].name"]
(being the first object and third object in the array with a name key with value matching "Data Analysis"
).
SET @mapJSON = '[{"id": 116298, "name": "Data Analysis", "language": "en"}, {"id": 5462, "name": "Visualization", "language": "00"}, {"id": 988, "name": "Data Analysis", "language": "es"}]';
SELECT JSON_SEARCH(@mapJSON, "all", "Data Analysis") as t WHERE JSON_VALID(@mapJSON)=1
Since your Value
is an array of objects:
[
{'id': 116298, 'name': 'Data Analysis', 'language': 'en'},
{'id': 5462, 'name': 'Visualization', 'language': '00'}
]
...each Value
should be a single object such as:
{'id': 116298, 'name': 'Data Analysis', 'language': 'en'}
...in which case you should get "Data Analysis"
when you run:
SET @mapJSON = '{"id": 116298, "name": "Data Analysis", "language": "en"}';
SELECT json_extract(@mapJSON,'$.name') as t WHERE JSON_VALID(@mapJSON)=1
[FYI: I'm using MySQL v8]