How to extract JSON value through SQL?

Viewed 40

"example_code": [ { "code": "blah", "type": "value" } ]

In other cases we would write : (meta->'example_code'->'code')

But, since it is inside [] braces, i am not able to extract.

1 Answers

Welcome to SO. Since example_code is an array use -> 0 to access its first (and only) element. Here is the documentation on it.
CTE the_table is a mimic of real data.

with the_table(meta) as 
(
 values ('{"example_code":[{"code":"blah", "type":"value"}]}'::json)
)
select meta -> 'example_code' -> 0 ->> 'code' from the_table;
Related