I have a JSON file that stores a Reddit post title along with its overall score:
{
"'JavaFX Simple Inventory Management App - Open source'": 39,
"'Creating Formula Dependency Maps from Excel Spreadsheets'": 5,
"'CVE-2017-5645: Apache Log4j socket receiver deserialization vulnerability'": 11
}
I can access this data easily and list it out to a DOM using this code:
$.getJSON("./data.json", function(json) {
var list = [];
/*Adds each key value pair to a `<li> tag`.*/
$.each(json, function(key, val) {
list.push("<li id='redditData'>" + key + ": " + val + "</li>");
});
/*Appends each data-filled `<li>` tag to a `<ul>` tag.*/
$("<ul>", {
"class": "data",
html: list.join("")
}).appendTo("#dataContainer");
});
However, I want to store the data with more precise information, showing an approximate upvote / downvote ratio, like so:
{
"'JavaFX Simple Inventory Management App - Open source'":
{"upvotes": 44.0, "downvotes": 7.0},
"'Creating Formula Dependency Maps from Excel Spreadsheets'":
{"upvotes": 3.0, "downvotes": 1.0},
"'CVE-2017-5645: Apache Log4j socket receiver deserialization vulnerability'":
{"upvotes": 12.0, "downvotes": 1.0}
}
How could I go about looping through this data and correctly display it?