0

I want to select some categories and sub categories and want to show it all in one array like this:

[
 {
   category: 'ELECTRONICS',
   sub_category: 'CONSOLE'
 }
]

but I got this:

[
    { f1: 'ELECTRONICS', f2: 'CONSOLE' },
    { f1: 'ELECTRONICS', f2: 'CONSOLE' }
  ]

here is a code snippet

      SELECT 

      s.id,
      s.name,
      s.image,
      s.verified,
      s.s_position,
      s.status,
      s.platform,
      s.coupon_name,
      s.coupon_pct,
      s.coupon_start,
      s.coupon_end,

      json_agg(row(c.category, scg.sub_category)) as categories

....
2

1 Answer 1

0
SELECT ...
     , json_agg(json_build_object('category', c.category
                                , 'sub_category', scg.sub_category)) as categories
...

See:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.