How to parse JSON in postgresql
I figured it out, guys
if I have a table books
I can easily write a query
SELECT
id,
data::json->'name' as name
FROM books;
And it will result in
I can also try to get non-existent column
SELECT
id,
data::json->'non_existant' as non_existant
FROM books;
And it this case I will get empty result
Awesome, thanks for sharing. I found that you can go deeper like:
SELECT
id,
data::json->'name' as name,
data::json->'author' ->> 'last_name' as author
FROM books;