Converting a JSON-stat response into a CSV file is trivial using the JSON-stat Javascript Utilities Suite.
Use Open in a new window to view the full dataset.
Converting a JSON-stat response into a CSV file is trivial using the JSON-stat Javascript Utilities Suite.
Use Open in a new window to view the full dataset.
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>From JSON-stat to CSV</title> | |
<meta charset="utf-8" /> | |
<script src="https://cdn.jsdelivr.net/combine/npm/jsonstat@0.13.13,npm/jsonstat-utils@2.5.5"></script> | |
<style type="text/css"> | |
.down { | |
display: inline-block; | |
padding: .5em; | |
background-color: #00f; | |
color: #fff; | |
cursor: pointer; | |
text-decoration: none; | |
} | |
.down:hover { | |
background-color: #000; | |
} | |
</style> | |
</head> | |
<body> | |
<a></a> | |
<pre></pre> | |
<script type="text/javascript"> | |
var url="https://json-stat.org/samples/oecd.json"; | |
JSONstat(url, function(){ | |
if(this.length){ | |
var | |
link=document.getElementsByTagName("a")[0], | |
pre=document.getElementsByTagName("pre")[0], | |
//CSV for English-speaking countries: comma as separator, dot as decimal mark | |
csv=JSONstatUtils.toCSV(this) | |
; | |
pre.innerHTML=csv; | |
if(typeof link.download!=="undefined"){ | |
link.href="data:text/csv;charset=utf-8," + encodeURIComponent(csv); | |
link.download="jsonstat.csv"; | |
link.className="down"; | |
link.innerHTML="Download CSV"; | |
}//Else: browser does not support the html5 download attribute | |
}else{ | |
window.alert("The response format is not JSON-stat!"); | |
} | |
}); | |
</script> | |
</body> | |
</html> |