# \[Solved\] Auto parse a ton of nested data?

**URL:** <https://forums.losant.com/t/solved-auto-parse-a-ton-of-nested-data/1391>\
**Category:** Help\
**Tags:** workflow, geofence\
**Created:** [January 1, 2019, 2:38am UTC](https://forums.losant.com/t/solved-auto-parse-a-ton-of-nested-data/1391 "2019-01-01T02:38:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Penney](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Christopher\_Penney](https://forums.losant.com/u/Christopher_Penney)\
**Post date:** [January 1, 2019, 2:38am UTC](https://forums.losant.com/t/solved-auto-parse-a-ton-of-nested-data/1391/1 "2019-01-01T02:38:40Z")

</div>

I have an HTTP node that is replying with a ton of nested values (233 in this case). I’d like to parse them out automatically so that I can quickly pass all the GPS values to a geofence polygon.  
I know its possible but cant figure out how. Any help welcome

 ![52%20PM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/64ed0397085f2e05b787780594defb804b451301.png)

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [January 2, 2019, 6:05pm UTC](https://forums.losant.com/t/solved-auto-parse-a-ton-of-nested-data/1391/2 "2019-01-02T18:05:49Z")

</div>

I would recommend a [Loop Node](https://docs.losant.com/workflows/logic/loop/) and pass it the `shell` array as the input. Inside the loop you’d add a [Geofence Node](https://docs.losant.com/workflows/logic/geofence/) to do the check. The Geofence Node takes a template, so you can combine the `lat` and `lng` values using the following template as the input to the Geofence Node:

```nohighlight
{{ working.item.value.lat }}, {{ working.item.value.lng }}

```

The above template makes an assumption that you put each object in the array on the `working.item` payload path in the Loop Node configuration.

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [January 2, 2019, 6:22pm UTC](https://forums.losant.com/t/solved-auto-parse-a-ton-of-nested-data/1391/3 "2019-01-02T18:22:48Z")

</div>

I had actually read your question as “How do I construct a geofence out of all these coordinates”, instead of how Brandon read it (“How do I check each coordinate against a geofence”). If the former is what you were after, then I built a simple workflow that would do what you’re looking for: deep looping over each of the arrays on your payload and building one geofence object. You can then reference that value by payload path in the Geofence Node.

Sample workflow is attached.

[coordinate-conversion-develop (1).flow](https://forums.losant.com/uploads/short-url/h2J7BAQ0E9Q5U63TMURxwGS1Lq9.flow) (6.6 KB)

---

<div class="post-metadata">

**Author:** ![Christopher\_Penney](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Christopher\_Penney](https://forums.losant.com/u/Christopher_Penney)\
**Post date:** [January 2, 2019, 9:53pm UTC](https://forums.losant.com/t/solved-auto-parse-a-ton-of-nested-data/1391/4 "2019-01-02T21:53:36Z")

</div>

Excellent thank you @Dylan_Schuster and @Brandon_Cannaday. Going to try the flow out - hadnt considered the deep loop. To be clear though I was hoping to pull all the separate “lat” “lng” values into a single object that could be passed to the geofence node to dynamically build a fence with one API call.  
Specifically passing into the geofence node: Polygonal Geofence (Payload Path) mode.

So, from the above image API return into below image automatically.

 ![04%20PM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/929485daf1c49f40fdbf42964644ace77c1aaa3e.png)

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [January 2, 2019, 9:58pm UTC](https://forums.losant.com/t/solved-auto-parse-a-ton-of-nested-data/1391/5 "2019-01-02T21:58:07Z")

</div>

@Christopher_Penney if `results` and `shapes` will each only ever have one item - as they do in your original example - you could dramatically simplify that workflow to just have one Loop Node, iterating over `data.body.results.0.shapes.0.shell`. I just built the nested loops in case your screenshot wasn’t of a typical workflow run in your application.

---

<div class="post-metadata">

**Author:** ![Christopher\_Penney](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Christopher\_Penney](https://forums.losant.com/u/Christopher_Penney)\
**Post date:** [January 3, 2019, 1:54am UTC](https://forums.losant.com/t/solved-auto-parse-a-ton-of-nested-data/1391/6 "2019-01-03T01:54:45Z")

</div>

Great works perfectly now thank you!  
I didnt realize that the payload path method of the geofence node would not return an image/embedded map like the other two methods - makes sense that it doesnt though as its payload dependent.  
That makes me wonder now if there is an easy way to transform the data.myGeofence values to an output that we can use in a mapbox embed (see code below)  
I feel like thats another loop on the data.myGeofence list and a transform to add the [] brackets, push to experience pageData, embed mapbox on a page, and pass it in with the {{ }} guys.

Is there any limit to loop layers? Is 4 too many? Feels like inception

> **[Add a GeoJSON polygon](https://docs.mapbox.com/mapbox-gl-js/example/geojson-polygon/)**
>
> Style a polygon with the fill layer type.

```auto
   map.addLayer({
        'id': 'maine',
        'type': 'fill',
        'source': {
            'type': 'geojson',
            'data': {
                'type': 'Feature',
                'geometry': {
                    'type': 'Polygon',
                    'coordinates': [[[-67.13734351262877, 45.137451890638886],
                        [-66.96466, 44.8097],
                        [-68.03252, 44.3252],
                        [-69.06, 43.98],
                        [-70.11617, 43.68405],
                        [-70.64573401557249, 43.090083319667144],
                        [-70.75102474636725, 43.08003225358635],
                        [-70.79761105007827, 43.21973948828747],
                        [-70.98176001655037, 43.36789581966826],
                        [-70.94416541205806, 43.46633942318431],
                        [-71.08482, 45.3052400000002],
                        [-70.6600225491012, 45.46022288673396],
                        [-70.30495378282376, 45.914794623389355],
                        [-70.00014034695016, 46.69317088478567],
                        [-69.23708614772835, 47.44777598732787],
                        [-68.90478084987546, 47.184794623394396],
                        [-68.23430497910454, 47.35462921812177],
                        [-67.79035274928509, 47.066248887716995],
                        [-67.79141211614706, 45.702585354182816],
                        [-67.13734351262877, 45.137451890638886]]]
                }

```

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [January 3, 2019, 3:14pm UTC](https://forums.losant.com/t/solved-auto-parse-a-ton-of-nested-data/1391/7 "2019-01-03T15:14:14Z")

</div>

It looks like Mapbox expects the format to be an array of arrays of arrays …

```auto
[ // these are each a separate polygon
  [ // these are sets of points that make a polygon
    [longitudeAsNumber, latitudeAsNumber], // each of these is a point
    ...
  ]
]

```

So yes, it would be quite easy to build this array using a modified version of the workflow I provided before. You’d want to create a new array within the innermost loop, cast your latitude and longitude to numbers (as they’re strings in your original data set), and insert them in the proper order (longitude first). Then push that new array into your `data.myGeofence` array (which itself should become an array nested in another array).
