This is the JSON object I'm querying:
const data =
{"fruit":["apple"],"vegetables":["carrot","turnip"],"dairy":["milk","cheese"]}'
Here's what I want to return in my postgres table:
category | item
--------------------
fruit | apple
vegetables | carrot
vegetables | apple
dairy | milk
dairy | cheese
This is what I've managed to do so far:
SELECT key as category, value as item
FROM json_each_text('${data}')
category | item
--------------------
fruit | ["apple"]
vegetables | ["carrot", "turnip"]
dairy | ["milk", "cheese"]
Does anybody know how to unnest/expand the values in the item column onto new rows? Thanks :)