Так же, как альтернатива.
Если вы Ajax файл на страницу,
fetch('Users.json').then(process);
вы можете сделать что-то вроде этого:
var tHead = document.getElementById("th"),
tBody = document.getElementById("tb"),
tr, td, text,
thr = document.createElement("tr"); // this is the table header row
// this whole thing goes away when you activate the fetch
var data = [{ "objID": "u7uSoWCPW8", "string": "bobby", "createdOn": "2018-09-17 08:08:30", "updatedOn": "2018-09-17 08:08:30", "number": 111, "boolean": true, "array": ["john", "sarah"], "pointer2": { "type": "__pointer", "objID": "dfg56FdE", "className": "Users" } }, { "objID": "rvLXpsN7Cb", "string": "bobby", "createdOn": "2018-09-17 09:03:30", "updatedOn": "2018-09-17 09:03:30", "number": 111, "boolean": true, "array": ["john", "sarah"], "pointer2": { "type": "__pointer", "objID": "dfg56FdE", "className": "Users" } } ]
function process(data) {
data.forEach(function(item, i) { // array
tr = document.createElement("tr"); // create the row
for (key in item) {
if (i === 0) { // save the THs from the first item
th = document.createElement("th");
th.innerHTML = key;
thr.appendChild(th);
}
text = []; // this is for the array and object in the item
if (typeof item[key] == "object") {
if (Array.isArray(item[key])) {
item[key].forEach(function(item2, j) { // Array forEach
text.push(item2)
});
} else {
for (key2 in item[key]) {
text.push(key2 + ":" + item[key][key2]); // Object for..in
}
}
} else {
text.push(item[key]); // everything else
}
td = document.createElement("td");
td.innerHTML = text.join("<br/>");
tr.appendChild(td);
}
tBody.appendChild(tr);
});
tHead.appendChild(thr);
}
process(data); // to be replaced with fetch('Users.json').then(process);
td {
border: 1px solid black;
}
<table>
<thead id="th"></thead>
<tbody id="tb"></tbody>
</table>