# Looping over array to change input of request - Where should the array be stored?

**URL:** <https://community.postman.com/t/looping-over-array-to-change-input-of-request-where-should-the-array-be-stored/27195>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [August 26, 2021, 10:38pm UTC](https://community.postman.com/t/looping-over-array-to-change-input-of-request-where-should-the-array-be-stored/27195 "2021-08-26T22:38:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cetspace25](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@cetspace25](https://community.postman.com/u/cetspace25)\
**Post date:** [August 26, 2021, 10:38pm UTC](https://community.postman.com/t/looping-over-array-to-change-input-of-request-where-should-the-array-be-stored/27195/1 "2021-08-26T22:38:15Z")

</div>

Context: New user (about 5 days) attempting to pass about 100 sets of lat/long coordinates via several requests (about 12) within a collection to an API on a monthly basis and manually inserting each lat/long coordinate in 12 GET requests is not feasible.

8 of the requests within the collection require a different set of lat/long coordinates - coordinates at another geographic level, i.e. Census Tract.

I already have the 100 latitude and longitude coordinates but currently just using two sets of latitude/longitude coordinates to develop the pre-request script, test scripts, variables, etc. and successfully run prior to using all 100 coordinates.

(I believe that it is possible to “auto-generate” the latitude and longitude coordinates for a particular geographical region and then feed this into the requests. This will be tackled later.)

Have reviewed the prior post titled “How to loop over array to change input of request?” and it mirrors about 80% of what I want to accomplish.

Steps taken so far include;

Modified the URL similar to the following format:  
https://…/bylocation?latitude={{latitudeArray}}&longitude={{longitudeArray}}

Created a CSV files with two lat/long coordinates

Utilized the Collection Runner

Imported the CSV file into Postman

Tried the above-mentioned steps numerous times and still receive the error

"JSONError: No data, empty input at 1:1 "

Any insight as to how this error can be resolved?

Thanks in advance.

Attached are the pertinent files:

 ![New Environment_Postman_20210826 - Copy](https://us1.discourse-cdn.com/getpostman/original/2X/2/227ab88ee0e782c6349e8f693d6611d19e2edc7e.png)

 ![001_Pre Request Script_Postman_20210826 - Copy](https://us1.discourse-cdn.com/getpostman/original/3X/9/5/95340affd868a6829b4ea03f1bbe6c4a5b1fbbbb.png)  
 ![001_Tests_Postman_20210826 - Copy](https://us1.discourse-cdn.com/getpostman/original/2X/0/023f900fed503a9e5f653e1fa81b1c45e9d1121c.png)

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [August 27, 2021, 4:45pm UTC](https://community.postman.com/t/looping-over-array-to-change-input-of-request-where-should-the-array-be-stored/27195/2 "2021-08-27T16:45:03Z")

</div>

Try breaking down your problem into smaller, more manageable steps.

"JSONError: No data, empty input at 1:1 "

indicates that whatever you have stored in those environment variables is not valid JSON. Most likely they are empty.

Create a more simple collection, work with [postman-echo.com](http://postman-echo.com) as a dummy API, use console.log to understand and debug your scripts.

---

<div class="post-metadata">

**Author:** ![cetspace25](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@cetspace25](https://community.postman.com/u/cetspace25)\
**Post date:** [August 28, 2021, 10:13pm UTC](https://community.postman.com/t/looping-over-array-to-change-input-of-request-where-should-the-array-be-stored/27195/3 "2021-08-28T22:13:39Z")

</div>

Thanks for the insight.

Just attempting to run one request within one collection as I concur - a modular approach is best.

Immediate goal is to successfully extract data for just one request using the environment variables within the Pre-request script;

latLongIndex  
latitudeArray  
longitudeArray

Then, will try the Data File approach.

Additional steps taken include;  
Switched from a POST request to a GET request  
Input the initial values for the variables “latitudeArray” and “longitudeArray”

Consistently receive the following error

“There was an error in evaluating the Pre-request Script:ReferenceError: Cannot access ‘latitudeArray’ before initialization”

With a limited, but expanding, frame of reference as it relates to Postman - it appears that the Environment variables are not processing.

Pertinent files displayed below.

Thanks in advance for any additional insight.

 ![002_Environment Variables_Postman_20210828 - Copy](https://us1.discourse-cdn.com/getpostman/original/2X/5/5c27eb9ff28aecab890f507de5ab7bacd6ac8471.png)  
 ![002_Pre Request Script_Postman_20210828 - Copy](https://us1.discourse-cdn.com/getpostman/original/2X/5/52b2272afa9b31bfe1c92267c6fe2995b498cfc8.png)  
 ![002_Tests_Postman_20210828 - Copy](https://us1.discourse-cdn.com/getpostman/original/2X/b/b4b3c6dcab94a12df67ef7b56708adf585e6c45e.png)

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [August 29, 2021, 6:21am UTC](https://community.postman.com/t/looping-over-array-to-change-input-of-request-where-should-the-array-be-stored/27195/4 "2021-08-29T06:21:45Z")

</div>

Try breaking down the script into even smaller pieces that you can understand. It is still too big.

I would remove everything and start from scratch.
