I am in the process of setting up a questionnaire using angularjs. I have an array of responses that looks like the following, and I need to convert this object array into JSON format. How do I go about converting an object array into JSON format?
var response=[
{"questiongroup":1,"question":1,"response":"response1"},
{"questiongroup":1,"question":2,"response":"response2"},
{"questiongroup":1,"question":3,"response":"response3"},
{"questiongroup":1,"question":4,"response":"response4"},
{"questiongroup":1,"question":5,"response":"response5"},
{"questiongroup":2,"question":6,"response":"response6"},
{"questiongroup":2,"question":7,"response":"response7"},
{"questiongroup":2,"question":8,"response":"response8"},
{"questiongroup":2,"question":9,"response":"response9"},
{"questiongroup":2,"question":10,"response":"response10"}
];
Desired Output:
{
"questiongroups": [
{
"questiongroup": 1,
"question": [
{"question": 1, "response": "response1"},
{"question": 2, "response": "response2"},
{"question": 3, "response": "response3"},
{"question": 4, "response": "response4"},
{"question": 5, "response": "response5"}
]
},
{
"questiongroup": 2,
"question": [
{"question": 6, "response": "response6"},
{"question": 7, "response": "response7"},
{"question": 8, "response": "response8"},
{"question": 9, "response": "response9"},
{"question": 10, "response": "response10"}
]
}
]
}