Looking to extract unique data from the JSON object below in order to create a result json with a list of questions and their corresponding choices. Any assistance would be greatly appreciated. Thanks in advance..!!
var data = [
{
"category": "sports",
"question": "Who is the best footballer?",
"questionType": "text",
"choices": "Messi",
"name": "Best Footballer",
"createdUserId": 1
},
{
"category": "sports",
"question": "Who is the best footballer?",
"questionType": "text",
"choices": "Ronaldo",
"name": "Best Footballer",
"createdUserId": 1
},
{
"category": "sports",
"question": "Who is the best footballer?",
"questionType": "text",
"choices": "Ibrahimovic",
"name": "Best Footballer",
"createdUserId": 1
},
{
"category": "sports",
"question": "Who is the top goal scorer?",
"questionType": "text",
"choices": "Messi",
"name": "Best Footballer",
"createdUserId": 1
},
{
"category": "sports",
"question": "Who is the top goal scorer?",
"questionType": "text",
"choices": "Ronaldo",
"name": "Best Footballer",
"createdUserId": 1
},
{
"category": "sports",
"question": "Who is the top goal scorer?",
"questionType": "text",
"choices": "Lewandoski",
"name": "Best Footballer",
"createdUserId": 1
}
];
Target JSON Format
{
"name": "Best Footballer",
"category": "sports",
"createdUserId": "1",
"questionList": [
{
"question": "Who is the best footballer?",
"questionType": "text",
"choices": [
"Messi",
"Ronaldo",
"Ibrahimovic"
]
},
{
"question": "Who is the top goal scorer?",
"questionType": "text",
"choices": [
"Messi",
"Ronaldo",
"Lewandoski"
]
}
]
}