0

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

1 Answer 1

1

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

Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.