0

I need to extract JSON element by index e.g.

SELECT JSON_EXTRACT('[{"featureId":"a","read":1,"write":1,"delete":1},{"featureId":"2","read":1,"write":0,"delete":1}]', '$[0].*');

But it just extracts the values I want extracted part to be like this:

{
    "featureId": "a",
    "read": 1,
    "write": 1,
    "delete": 1
}
2
  • You can use select JSON_OBJECT('[{"featureId":"a","read":1,"write":1,"delete":1},{"featureId":"2","read":1,"write":0,"delete":1}]', '$[0].*'); Commented Mar 2, 2018 at 6:31
  • it does not work. It returns complete json Commented Mar 2, 2018 at 6:37

1 Answer 1

1

Try:

SELECT JSON_EXTRACT('
  [
    {"featureId":"a","read":1,"write":1,"delete":1},
    {"featureId":"2","read":1,"write":0,"delete":1}
  ]
', '$[0]');

See db-fiddle.

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.