0

I have an array of json -

[{id:1,quantity:100},{id:2,quantity:25},{id:3,quantity:68}]

How do convert this into following using query in postgres -

Id     |Quantity
-----------------
1      |100
2      |25
3      |68

If it is at all possible, I want to know how

1 Answer 1

2

Use jsonb_array_elements()

select t ->> 'id' as id, t ->> 'quantity' as quantity
from jsonb_array_elements('[{"id":1,"quantity":100},{"id":2,"quantity":25},{"id":3,"quantity":68}]') as t

Online example: https://rextester.com/YBUER58387

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.