PostgreSQL – Convert Multiple Rows into JSON

jsonpostgresqlselect

Looks my question is unusual because I didn't find the answer at all.
Let's imagine, I have table A with columns: language and uri.

language | uri             
---------|-----------------
ru       | some-uri        
en       | some-another-uri
...

My question is: How can I return JSON object instead of many rows.
E.g.:

{
"ru": "some-uri",
"en": "some-another-uri",
...
}

Best Answer

So, I found out the answer far far away in the documentation.

SELECT json_object(array_agg(language), array_agg(uri)) FROM A will give you the expected result.