The JSON-stat Javascript Toolkit is also available as an ECMAScript module (export.mjs). This example shows how to retrieve the latest post-Brexit EU unemployment rate using the JTT module.
Last active
May 17, 2020 06:28
-
-
Save badosa/0e66d01e4e889c0e7eb70135ee132147 to your computer and use it in GitHub Desktop.
JJT ECMAScript module example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>JJT ECMAScript module example</title> | |
<style> | |
body { | |
padding: 20px 40px; | |
font-size: 30px; | |
} | |
</style> | |
</head> | |
<body> | |
<main> | |
<p>What: <strong>Unemployment rate (%)</strong></p> | |
<p>Where: <strong class="geo">...</strong></p> | |
<p>When: <strong class="time">...</strong></p> | |
<p>How much: <strong class="value">...</strong></p> | |
</main> | |
<script nomodule> | |
//For old browsers not supporting ES modules | |
window.alert("Sorry, your browser does not support ECMAScript modules!"); | |
</script> | |
<script type="module"> | |
import { JSONstat } from "https://unpkg.com/jsonstat@0.13.13/export.mjs"; | |
//or https://cdn.jsdelivr.net/npm/jsonstat@0.13.13/export.mjs | |
const | |
url="https://ec.europa.eu/eurostat/wdds/rest/data/v2.1/json/en/une_rt_a?precision=1&sex=T&lastTimePeriod=1&geo=EU27_2020&unit=PC_ACT&age=Y15-74", | |
main=async function(url){ | |
const | |
res=await fetch(url), | |
json=await res.json(), | |
stat=JSONstat(json) | |
; | |
document.querySelector(".geo").innerText=stat.Dimension("geo").Category(0).label; | |
document.querySelector(".time").innerText=stat.Dimension("time").Category(0).label; | |
document.querySelector(".value").innerText=stat.value[0]; | |
} | |
; | |
main(url); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment