I'm using Postgres database and have a table as below
Table Name: Test
id firstname lastname
1 Sam Crews
2 John Dave
I'm trying to get result set back in below JSON format but with no luck
Expected:
[{"1": {"firstname": "Sam", "lastname": "Crews"}},
{"2": {"firstname": "John", "lastname": "Dave"}}
]
I tried using row_to_json, json_build_object functions but the output is bit different (as below).
Actual:
[{"id": "1", "firstname": "Sam", "lastname": "Crews"},
{"id": "2", "firstname": "John", "lastname": "Dave"}
]
Any pointers on how to achieve expected result would be greatly appreciated.
Thank you!