Trouble pulling data from JSON

working on D3 project:

I’m struggling being able to read in the JSON data with:

d3.json("https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json", function(data) {
  console.log(data.data[0])  
});

the console shows nothing, and if I try to work with (data) it appears to not be working. What am I doing wrong?

Try it like this.

d3.json(“https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json”).then((data)=>console.log(data.data[0]))

I logged d3.json function after invoked with url argument and saw a promise so I figured it was “thenable”

They must’ve changed it since verison 4. I tried to look through the docs for about 10 seconds to find the actual documentation to see what else they might’ve added but I remembered d3’s docs gave me nightmares, so I’ll leave the rest to you.

1 Like

Any idea why it wouldn’t work without “then”? The example they provide uses d3.json without it:

Yes. I stated why I think it’s not working. That FCC example is using version 4.2.2. I’m assuming you are using 5 or greater and that’s why the json call wasn’t working in that fashion.

EDIT : Here you go:

1 Like