# Node-red json parsing

**URL:** <https://discourse.nodered.org/t/node-red-json-parsing/45930>\
**Category:** General\
**Created:** [19 May 2021 15:18 UTC](https://discourse.nodered.org/t/node-red-json-parsing/45930 "2021-05-19T15:18:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rnevi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rnevi/32/42054_2.png) [@rnevi](https://discourse.nodered.org/u/rnevi)\
**Post date:** [19 May 2021 15:18 UTC](https://discourse.nodered.org/t/node-red-json-parsing/45930/1 "2021-05-19T15:18:38Z")

</div>

Hello,  
I am new to node-red and i have a Json file with multiple arrays:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0be15049d56bd86b47376cafcd673d10cc49a2f1.png)  
and i want to iterate them all in a nested loop so i can save the values inside a list.  
so far i managed to iterate one array and save the values to a list but i cannot go through multiple arrays for some reason  
This is what i have so far:

```auto
for (var i=0; i<=data.features[0].geometry.coordinates.length; i++){
    for (var j=0; j<=data.features[0].geometry.coordinates[i].length; j++)
        spots.push(data.features[0].geometry.coordinates[i][j]);
}

```

and i get the following error:

```auto
TypeError: Cannot read property 'length' of undefined

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 May 2021 15:22 UTC](https://discourse.nodered.org/t/node-red-json-parsing/45930/2 "2021-05-19T15:22:03Z")

</div>

> [@rnevi](#):
>
> `<=`

Change the `<=` to `<` in the for loops.

You are going past the end of the array.

---

<div class="post-metadata">

**Author:** ![rnevi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rnevi/32/42054_2.png) [@rnevi](https://discourse.nodered.org/u/rnevi)\
**Post date:** [19 May 2021 16:22 UTC](https://discourse.nodered.org/t/node-red-json-parsing/45930/3 "2021-05-19T16:22:54Z")

</div>

That worked! Thank you very much!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [19 May 2021 17:20 UTC](https://discourse.nodered.org/t/node-red-json-parsing/45930/4 "2021-05-19T17:20:26Z")

</div>

For future reference, there are much easier ways to iterate an array.

```auto
msg.payload.features.forEach( feature => {
  feature.geometry.coordinates.forEach( coord => {
    // .... and so on ....
  })
})
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 June 2021 17:21 UTC](https://discourse.nodered.org/t/node-red-json-parsing/45930/5 "2021-06-02T17:21:13Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
