Reputation: 744
Given an array of jsons I want to extract a given key from object object
e.g:
extract 'Name' key
'[{"Name": "Homer", "Age": 39}, {"Name": "Marge", "Age": 40}]' --->["Homer" , "Marge"]
My attempt
SELECT JSON_EXTRACT('[{"Name": "Homer", "Age": 39},
{"Name": "Marge", "Age": 40}]','$.Name');
returns null
Im using mysql 5.7.23
Upvotes: 0
Views: 876
Reputation: 65198
You just need square bracketed notation such as '$[*].Name'
while formatting the second argument as JSON value is nested within them
SELECT JSON_EXTRACT('[{"Name": "Homer", "Age": 39},
{"Name": "Marge", "Age": 40}]','$[*].Name') AS names
Upvotes: 1