I have the following SQL table
user_id product_1 product_2 product_3
123 Scissors Stone Paper
I wrote this code to format result as JSON, but can't get it in the desired format. If i name all product columns as name then sql returns an error
Use different names and aliases for each column in SELECT list.
Sql code:
select
product1 as 'Product1',
product2 as 'Product2',
product3 as 'Product3'
from Recommendations
where user_id = '123'
FOR JSON PATH, ROOT('Offers')
Current output:
{"offers":[
{"Product1": "Scissors", "Product2": "Stone", "Product3": "Paper"}
]
}
Desired output:
{"offers":[
{"name": "Scissors"},
{"name": "Stone"},
{"name": "Paper"}
]
}