I’m trying to get the data from a https.get request to an API and the json path has a 0 at the beginning. What does it mean and how do I access the data?
JavaScript
x
5
1
https.get(url, function(response) {
2
response.on("data", function(data) {
3
readableData = JSON.parse(data);
4
length = readableData.0.length; // <-- inserting path (0.length) here doesnt work as usually
5
The path is 0.length and the json chart viewer throws an error.
The data looks like this in json viewer:
JavaScript
1
6
1
[
2
{
3
"length": "32260db8-40d3-4973-9031-ceef149189aa",
4
}
5
]
6
Advertisement
Answer
0
is index of array, to get length of the array do
JavaScript
1
2
1
readableData.length; // 1
2
to select first array do
JavaScript
1
2
1
readableData[0].length; // 32260db8-40d3-4973-9031-ceef149189aa
2