https://supabase.com/ logo
#sql
Title
# sql
g

garyaustin

04/30/2022, 2:22 PM
json_build_object takes a list parameter, json_object takes a text array with pairs of items or array of two item arrays to build key:value object.
From: https://www.postgresql.org/docs/9.5/functions-json.html
Copy code
json_object('{a, 1, b, "def", c, 3.5}')
json_object('{{a, 1},{b, "def"},{c, 3.5}}')
{"a": "1", "b": "def", "c": "3.5"}
Note {} is Postgres array in first two
m

Muezz

04/30/2022, 2:38 PM
From what is looks like, both json_object and json_build_object make the same kind of output. The only difference is that one takes an array of elements OR key value pairs and the other takes the elements itself as argument. Is that correct?
g

garyaustin

04/30/2022, 2:39 PM
yes
It also looks like json_object if given two arrays will pair them up as key value from each array.
m

Muezz

04/30/2022, 2:48 PM
well thanks for the reply. It is working great now. I dont even need
json_build_object
.