I'm looking to create single JSON object per grouped field, and trying to use json_build_object for that purpose. However, the return result is multiple json values instead.
Below is the code
with t(product, key, value) as
(
values
('A','category', 'food'),
('A','price', '4.00'),
('B','category', 'book'),
('B','price', '20.00'),
('B','genre', 'Sci-Fi')
)
select product, json_build_object(key, value) from t
group by product, key, value
and the result received is
"A" | "{""price"" : ""4.00""}"
"A" | "{""category"" : ""food""}"
"B" | "{""genre"" : ""Sci-Fi""}"
"B" | "{""category"" : ""book""}"
"B" | "{""price"" : ""20.00""}"
What I want as result is
"A" | "{ 'price' : 4.00, 'category': 'food' }"
"B" | "{ 'genre' : 'Sci-Fi', 'category': 'book', 'price': 20.00 }"