postgesql returns the json_build_object as a parent for each grouped json array like this:
{
"status": "success",
"stories": [{
"json_build_object": {
"CNN": []
}
},
{
"json_build_object": {
"FOX": []
}
},
{
"json_build_object": {
"Huffpost": []
}
},...
Postgresql returns the "json_build_object" as a key. Is it possible to replace with the stories.source value returned by the group by?
SELECT json_build_object(source, json_agg(stories.*))
FROM stories
GROUP BY stories.source
ORDER BY source;
Optimal solution would be a response like this:
stories:
CNN: [],
FOX: []...
I'm sure I'm missing a best practice for returning JSON in Postgresql...