0

Is it possible to turn a json array (["a","b","c"]) column into a json object ({"a":"a", "b":"b", "c":"c"}) in postgresql?

1 Answer 1

2

Unnest the array with jsonb_array_elements_text() and aggregate the elements back using jsonb_object_agg():

select jsonb_object_agg(value, value)
from jsonb_array_elements_text('["a","b","c"]'::jsonb);

        jsonb_object_agg        
--------------------------------
 {"a": "a", "b": "b", "c": "c"}
(1 row) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.