I have a JSON file named info.json which have personal info of 20 students, and I want to convert it to a HTML table.
This is just an example(info of just 1).This goes for 20 students.This is HTML table headings only.This is how I want my table 's layout. I couldn 't give here what I tried due to some error. This is upto what I have tried.
[{
"student_name": "Shastri Mahesh",
"date_of_birth": "03-02-2002",
"parents": [{
"father_name": "Shidharth Mahesh",
"mother_name": "Suhana"
}],
"blood_group": "AB-",
"email": "[email protected]",
"phone": [{
"landline": 9812343541,
"mobile": 908252123
}],
"address": [{
"door_no": "3A",
"street_name": "Shastri nagar",
"place_name": "Delhi",
"pin_code": 142342,
"country": "India"
}],
"degree": [{
"ug": true,
"pg": true,
"others": "PhD(English Hons.)"
}]
}]
$(document).ready(function() {
// FETCHING DATA FROM JSON FILE
$.getJSON("info.json", function(data) {
var student = '';
// ITERATING THROUGH OBJECTS
$.each(data, function(key, value) {
//CONSTRUCTION OF ROWS HAVING
// DATA FROM JSON OBJECT
student += '<tr>';
student += '<td>' + value.student_name + '</td>';
student += '<td>' + value.date_of_birth + '</td>';
student += '<td>' + value.parents.father_name + '</td>';
student += '<td>' + value.parents.mother_name + '</td>';
student += '<td>' + value.blood_group + '</td>';
student += '<td>' + value.email + ',' + '<br>' + value.phone.landline + ',' + value.phone.mobile + '</td>';
student += '<td>' + value.address.door_no + ',' + value.address.street_name + ',' + value.address.place_name + ', <br>' + value.address.country + '-' + value.address.pin_code + '</td>';
student += '<td>' + value.degree.ug + '</td>';
student += '<td>' + value.degree.pg + '</td>';
student += '<td>' + value.degree.others + '</td>';
student += '</tr>';
});
//INSERTING ROWS INTO TABLE
$('#table').append(student);
});
});