Garmaine Staff asked 2 years ago

I am guessing my terminology in the following post is wrong. I am generally new to using APIs.

I am using an API from the Census Bureau that returns a list of of objects in JSON format. The issue I am having with this particular API is that it appears the arrays are nested within arrays that don't have names or any way to find a path through to the object.

Here is what the API query returns:

[
[
"DRRALL",
"CRRINT",
"RESP_DATE",
"CRRALL",
"GEO_ID",
"DRRINT",
"state"
],
[
"0.4",
"37.1",
"2020-04-10",
"41.4",
"0400000US36",
"0.4",
"36"
]
]

I am trying to obtain the date the information was queried and the response rate, but I just have never see JSON in this format. I checked to make sure it is valid JSON, and it is. I tried peeling away layer by layer, but I end up with undefined or empty arrays when attempting to push it to another variable.

Here is as close as I've gotten to the desired results:


fetch(url)
  .then((resp) => {
    return resp.json();
  })

  .then((data) => {
    stateArray.push(data[1]);
  });

console.log(stateArray);

Here's the result of my console log:

[]
​0: (7) […]
​​0: "0.4"
​​1: "37.1"
​​2: "2020-04-10"
​​3: "41.4"
​​4: "0400000US36"
​​5: "0.4"
​​6: "36"
length: 7
<prototype>: Array []
length: 1

As you'll see, there is another empty array just before the array with my desired objects.

Any help would be great.

Thanks!