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

Ansible warning on jinja2 braces on when -

Parsing a protocol message from Go by Java -

html - How to custom Bootstrap grid height? -