I want to run a script that takes in a JSON file, performs a function on it to extract and format selected data into one variable ($history)
to then render in the HTML. The format of the JSON file is:
{123: {"epochBlocks": 0, "blocks": 0, ..."}, "updatedAt": "2323432" <- (key I want to skip), ...}
My code for the script:
let $history = "";
$.getJSON(
"https://pooltool.s3-us-west-2.amazonaws.com/8e4d2a3/pools/bd1d1aafead6f652f76f5921b4ffdb429d7eb9d5322d0f4700f4f70f997c5a82/epochstats.json"
).done(function (data) {
$.each(data.items, function (i, item) {
// if (!data.items[i].includes(/[\w]/gi)) { //if key does not contain letters, do below:
$history = $history + data[item].epochBlocks + "/" + data[item].blocks + "\n";
// }
});
});
$("#history").text($history);
At the end of the script I use $("#history").text($history)
to render it in HTML with <span id="history"></span>
.
I am getting no output using the above code. The URL for the JSON file is downloadable, so I am not sure if the script can read it? I also thought something might be wrong with my if statement so I commented it out and there is still no output. Please point me to the issue - my code or the JSON url being auto-download? Thanks.