Importing local json file using d3.json does not work
If you're running in a browser, you cannot load local files.
But it's fairly easy to run a dev server, on the commandline, simply cd
into the directory with your files, then:
python -m SimpleHTTPServer
(or python -m http.server
using python 3)
Now in your browser, go to localhost:3000
(or :8000
or whatever is shown on the commandline).
The following used to work in older versions of d3:
var json = {"my": "json"};d3.json(json, function(json) { root = json; root.x0 = h / 2; root.y0 = 0;});
In version d3.v5, you should do it as
d3.json("file.json").then(function(data){ console.log(data)});
Similarly, with csv and other file formats.
You can find more details at https://github.com/d3/d3/blob/master/CHANGES.md
Adding to the previous answers it's simpler to use an HTTP server provided by most Linux/ Mac machines (just by having python installed).
Run the following command in the root of your project
python -m SimpleHTTPServer
Then instead of accessing file://.....index.html
open your browser on http://localhost:8080
or the port provided by running the server. This way will make the browser fetch all the files in your project without being blocked.