JSON
A simple example that tries to demonstrate how a
JSON document can be read with
D3.js.
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<title>Reading JSON with D3.js</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/7.6.1/d3.min.js"></script>
<script>
d3.json('data.json').
then(function(jsn){
alert("txt = " + jsn.txt + "\n" + "num = " + jsn.num);
}).
catch(function(err) {
alert("Error: " + err);
});
</script>
</body>
</html>
This is the document:
{
"num": 42,
"txt": "Hello world"
}
In order to test this example on a local computer, a CORS capable
webserver must be started (for example
with Python).