function jsonToHtml(jsonData) {

	// console.log(jsonData);

	localStorage.setItem('scroll', 1)
	localStorage.setItem('EditNavExpend', 1)


	const count = jsonData.sections.length;
    // console.log(`Count of sections: ${count}`);

	
	
	if(jsonData == "" || jsonData == null)
	{

	document.getElementById('Question_title').querySelector('.ql-editor').innerHTML = "";
	document.getElementById('Question_description').querySelector('.ql-editor').innerHTML = "";
	document.getElementById('Max_Marks').value = "";
	document.getElementById('Course_ID').value = "";
	document.getElementById('Course_Code').value = "";
	document.getElementById('Subject_ID').value = "";
	document.getElementById('Subject_Code').value = "";
	document.getElementById('Paper_No').value = "";
	document.getElementById('Subject_Name').value = "";
	document.getElementById('Sub_Paper_Prefix').value = "";

	}
	else
	{
	var title = jsonData.question_paper_title;
	var description = jsonData.question_paper_description;
	var question_Paper_uuid = jsonData.attributes.Id;
	var max_marks = jsonData.attributes.MaxMarks;
	var course_ID = jsonData.attributes.CourseId;
	var course_Code = jsonData.attributes.CourseCode;
	var subject_ID = jsonData.attributes.SubjectId;
	var subject_Code = jsonData.attributes.SubjectCode;
	var paper_No = jsonData.attributes.PaperNo;
	var subject_Name = jsonData.attributes.SubjectName;
	var sub_Paper_Prefix = jsonData.attributes.SubPaperPrefix;
	document.getElementById('Question_title').querySelector('.ql-editor').innerHTML = title;
	document.getElementById('Question_description').querySelector('.ql-editor').innerHTML = description;
	document.getElementById('Max_Marks').value = max_marks;
	document.getElementById('Course_ID').value = course_ID;
	document.getElementById('Course_Code').value = course_Code;
	document.getElementById('Subject_ID').value = subject_ID;
	document.getElementById('Subject_Code').value = subject_Code;
	document.getElementById('Paper_No').value = paper_No;
	document.getElementById('Subject_Name').value = subject_Name;
	document.getElementById('Sub_Paper_Prefix').value = sub_Paper_Prefix;
	document.getElementById('QuestionPaper_UUID_ID').value = question_Paper_uuid;

	}
	jsonData.sections.forEach(function(section, index) {
        
		const random_no = Date.now();
		var questionAreaId = 'question_area_'+random_no; //Add section to this id of the question paper
        
		var sectionTitle = section.section_title;
		var sectionDescription = section.section_description;
		var sectionMarks = section.section_marks;
		var sectionUUID = section.attributes.Id;
		var sectionDispalyMarks = section.section_display_marks;
		var sectionAttemptAny = section.section_attempt_any;


		var SectionObj = {         
			'random_no'          :random_no,
			'sectionTitle'       :section.section_title,
		    'sectionDescription' :section.section_description,
			'sectionMarks'       :section.section_marks,
			'sectionUUID'        :section.attributes.Id,
			'sectionDispalyMarks':section.section_display_marks,
			'sectionAttemptAny'  :section.section_attempt_any,
		}

	// addSection(SectionObj); //call the addSection() function and send the sectionObject to that function
	addSection(sectionTitle, sectionDescription, random_no, sectionUUID, sectionMarks, sectionDispalyMarks, sectionAttemptAny);

	section.questions.forEach(function(Question, index) {

        const questionRandomNo = Date.now();
	    QuestionsForEach(Question, questionAreaId, questionRandomNo)
    
    })

	})
	localStorage.removeItem('scroll');
	localStorage.removeItem('EditNavExpend');
}


function QuestionsForEach(Question, questionAreaId, questionRandomNo){

    var questionTypeFormets = "";		
	if(Question.question_type)
	{
		questionTypeFormets = Question.question_type;
	}	
	else
	{
		questionTypeFormets ='question_group';
	}
	var questionTitle        = Question.question;
	var questionDescription  = Question.question_description;
	var questionType         = questionTypeFormets;
	var questionSubType      = Question.question_sub_type;
	var mathEnabled          = Question.is_math_enabled;
	var questionMarks        = Question.marks;
	var questionUUID         = Question.attributes.Id;
	var questionDisplayMarks = Question.display_marks;
	var Choice               = Question.answers;
	

	var QuestionObj = {         
		"question_area_id"     :questionAreaId,
		'questionRandomNo'     :questionRandomNo,

		'questionTitle'        :Question.question,
		'questionDescription'  :Question.question_description,
		'questionType'         :questionTypeFormets,
		'questionSubType'      :Question.question_sub_type,
		'mathEnabled'          :Question.is_math_enabled,
		'questionMarks'        :Question.marks,
		'questionUUID'         :Question.attributes.Id,
		'questionDisplayMarks' :Question.display_marks,
		'Choice'               :Question.answers,
	}
				
											
	if(questionType == 'text')
	{
		textQuestion(QuestionObj)
		// textQuestion(false, false, false, questionTitle, questionDescription, questionSubType, mathEnabled, questionAreaId, questionRandomNo, questionMarks, questionUUID, questionDisplayMarks);
	}
	else if (questionType == 'group')
	{  							
		groupQuestion(false, false, false, questionTitle, questionDescription, questionType, questionSubType, mathEnabled, Choice, questionAreaId, questionRandomNo, questionMarks, questionUUID, questionDisplayMarks,);
		// groupQuestion(QuestionObj);


		Choice = Choice.slice(1);
		Choice.forEach(function(choicenames, index) {
		var choiceName = choicenames.choice_name;
		var choiceID = choicenames.id;
		var choice_mathEnabled = choicenames.is_math_enabled;
				
		addNewChoice(false , false, choiceName, questionRandomNo, choiceID, choice_mathEnabled);

		});
	}
	else if (questionType == 'question_group')
	{   
		
		generateGroupQuestion(Question, questionAreaId, questionRandomNo);
		
	}

}


//function for Generate QuestionGroup 
function generateGroupQuestion(Question, questionAreaId, questionRandomNo)
{
   
		var idObj = {"section_question_area_id":questionAreaId, 'question_group_obj': Question, 'questions_randon_id':questionRandomNo};

		addQuestionGroup(idObj);
		
		Question.questions.forEach(function(GroupQuestions, index) {
			const QuestionGroupRandomNo = Date.now();
			var questionGroupAreaId = 'group_question_area_'+questionRandomNo;
			QuestionsForEach(GroupQuestions, questionGroupAreaId, QuestionGroupRandomNo);
});
}
