I am trying to recreate this json using json_build_object and json_build_array in postgresql
Here is my desired output:
[
{
"name": "Albert",
"Gender": "Male",
"tags": [
"Student",
"Geography"
]
}
]
Here is my query:
SELECT
json_build_array(json_build_object(
'tags',jsonb_build_array('Student','Geography'),
'Gender','Male',
'name', 'name'
))
FROM student_list
But when I run this query I get the Gender part appearing first and not like my desired output.
Here is the output I get after running my query
[
{
"Gender": "Male",
"name": "Albert",
"tags": [
"Student",
"Geography"
]
}
]
What can I do to get it like my desired output and why is not following the order in my query. I tried to rearrange the statements in the query but I noticed that the Gender always will pop first and not like my desired output.
Can someone tell me what I am doing wrong.