Sample Header Ad - 728x90

Postgres query to return JSON object keys as array

19 votes
1 answer
41642 views
Is it possible to return a JSON object keys as an array of values in PostgreSQL? In JavaScript, this would simply be Object.keys(obj), which returns an array of strings. For example, if I have a table like this: tbl_items --------- id bigserial NOT NULL obj json NOT NULL And if there's a row like this: id obj ----- ------------------------- 123 '{"foo":1,"bar":2}' How can I have a query to return: id keys ----- ------------------ 123 '{"foo","bar"}'
Asked by Yanick Rochon (1651 rep)
Jan 25, 2016, 02:51 PM
Last activity: Nov 26, 2024, 09:15 PM