I have a string having multiple choice question and answers as follows:
(1) Capital of Bangladesh is-
(A) Dhaka (B) Rangpur (C) Chittagong (D) Comilla। Ans (A) Dhaka
(2) Largest city of Bangladesh is-
(A) Mirpur (B) Rangpur (C) Chittagong (D) Comilla। Ans (C) Chittagong
(3) Smallest city of Bangladesh is-
(A) Dhaka (B) Rangpur (C) Chittagong (D) Meherpur। Ans (B) Rangpur
I need to create json from the above string so that it create separate questions with answers
The final json will be like:
{"questions":
[
{
"options":["Dhaka","Rangpur","Chittagong","Comilla"],
"body":"Capital of Bangladesh is-",
"answers":["A"]
},
{
"options":["Mirpur","Rangpur","Chittagong","Comilla"],
"body":"Capital of Bangladesh is-",
"answers":["C"]
}
]
}
I tried with
var result = reader.result.split('\n');
for (var index = 0; index < result.length; index++) {
var question = result[index]
if(question.match("/[(/)]/g")){
questions.push = question
}
else {
questions.push = question
}
}
console.log(questions)
How can I make it