<!DOCTYPE html>
<htmll lang="ru">
<head>
<title>Untitled</title>
<meta charset="utf-8">
</style>
</style>
</head>
<body>
<textarea id=ijs rows=15 cols=40 placeholder="Copy your JSON here"></textarea>
<br><br>
<button id=bt>Correct JSON</button>
</body>
<script>
const correctJson = (ojso) =>{
const njso = [];
let tmpo = null;
for (let ob of ojso) {
if ('QUESTION' in ob) {
if (tmpo) njso.push(tmpo);
tmpo = {QUESTION: ob.QUESTION, ANSWERS:[ob.ANSWERS], CORRECT:ob.CORRECT.split(',').map(v => +v)}
} else {
tmpo.ANSWERS.push(ob.ANSWERS)
}
}
if (tmpo) njso.push(tmpo);
return njso;
}
document.getElementById('bt').addEventListener('click', () => {
const oldJson = JSON.parse(document.getElementById('ijs').value)
document.getElementById('ijs').value = JSON.stringify(correctJson(oldJson))
})
</script>
</html>