1

I am trying to generate a single json by querying from a table with id as key and email as value like this

{1: "abc@example.com", 2: "abcd@example.com"}

My attempt to create is:

select json_agg(json_build_object(id, email)) 
from auth_user 
where id in (4733, 3625, 4961, 4237);

which results me

[{4733: "abc@example.com"}, {3625: "abcd@example.com"}]

1 Answers1

1

Migrating a comment to an answer.

I think you are looking for json_object_agg not json_agg – a_horse_with_no_name 2 hours ago

Links

Evan Carroll
  • 65,432
  • 50
  • 254
  • 507