json - Return Postgres json_build_object as variable field from table -


postgesql returns json_build_object parent each grouped json array this:

 {   "stories": [{         "json_build_object": {           "cnn": []         }       },       {         "json_build_object": {           "fox": []         }       },       {         "json_build_object": {           "huffpost": []         }       },... 

postgresql returns "json_build_object" key. possible replace stories.source value returned group by? tried alias returned error.

select json_build_object(source, json_agg(stories.*)) stories group stories.source order source; 

optimal solution response this:

 stories:   cnn: [],   fox: []... 

i'm sure i'm missing best practice returning json in postgresql...


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -