Решено
$('#upload').on('click', function() {
$('.question').each(function(i){
var cur_el = $(this);
var question = cur_el.attr('data-question');
testList[i] = {
testName : 'Тест',
questionsList : {
question : question,
answerList : {}
}
};
cur_el.find('.answer').each(function(y){
var answer = $(this).attr('data-answer');
testList[i]['questionsList']['answerList'][y] = {answer : answer};
});
});
console.log(testList);
});