Postgres parse json stored as string

Viewed 21

I have a json column in in the following table (my_table) which I have json saved as string, for example:

index json_col
1 "{\"alpha\": {\"beta\": \"gamma\"}}"

I would like to query let's say beta from it.

1 Answers

After some fiddling around I finally managed to figure this out:

select ((json_col::JSONB)->>0)::JSONB
from my_table

This will first get the first element of the string which is json and then cast it to json.

Related