# How to deal with input JSON with varying array lengths when reading from external file

**URL:** <https://community.postman.com/t/how-to-deal-with-input-json-with-varying-array-lengths-when-reading-from-external-file/11491>\
**Category:** Help Hub\
**Created:** [March 23, 2020, 6:19pm UTC](https://community.postman.com/t/how-to-deal-with-input-json-with-varying-array-lengths-when-reading-from-external-file/11491 "2020-03-23T18:19:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbraus](https://avatars.discourse-cdn.com/v4/letter/d/74df32/32.png) [@dbraus](https://community.postman.com/u/dbraus)\
**Post date:** [March 23, 2020, 6:19pm UTC](https://community.postman.com/t/how-to-deal-with-input-json-with-varying-array-lengths-when-reading-from-external-file/11491/1 "2020-03-23T18:19:50Z")

</div>

I have a situation where I’m sending JSON input payloads to my API that have arrays whose lengths can vary. I am wondering how to best deal with this when using an external file to populating my request body.

I put a couple snippets of example request bodies - but basically, the “components” , “faultCodes” , “sensors” , “measurements” arrays can all be of varying length (all of which are valid inputs).

So if I want to pull these request bodies in from an external file and have postman iterate through them, how do I need to structure the request body in postman to accept the varying JSON coming from the external file?

For example:  
**Request body 1:**  
{  
“TestId”: “00”,  
“comp”: [  
{  
“comptName”: “5.01”,  
“fault”: [  
{  
“faultKey”: “1X”,  
“faultValue”: 1  
},  
{  
“faultKey”: “2X”,  
“faultValue”: 2  
},  
],  
“sensors”: [  
{  
“SerialNumber”: “600607”,  
“measurements”: {  
“LFrequency”: {  
“x”: {  
“unit”: “G”  
},  
“y”: {  
“unit”: “G”  
},  
“z”: {  
“unit”: “G”  
},  
},  
}  
}  
]  
}  
],  
}

**Request body 2:**  
{  
“TestId”: “00”,  
“comp”: [  
{  
“compName”: “5.01”,  
“fault”: [  
{  
“faultKey”: “1X”,  
“faultValue”: 1  
},  
{  
“faultKey”: “2X”,  
“faultValue”: 2  
},  
{  
“faultKey”: “3X”,  
“faultValue”: 3  
},  
],  
“sensors”: [  
{  
“SerialNumber”: “607”,  
“measurements”: {  
“LowFrequency”: {  
“x”: {  
“unit”: “G”  
},  
“y”: {  
“unit”: “G”  
},  
“z”: {  
“unit”: “G”  
},  
},  
}  
}  
{  
“SerialNumber”: “600608”,  
“measurements”: {  
“LowFrequency”: {  
“x”: {  
“unit”: “G”  
},  
“y”: {  
“unit”: “G”  
},  
“z”: {  
“unit”: “G”  
},  
},  
}  
}  
]  
}  
{  
“compName”: “5.02”,  
“fault”: [  
{  
“faultKey”: “1X”,  
“faultValue”: 1  
},  
{  
“faultKey”: “2X”,  
“faultValue”: 2  
},  
],  
“sensors”: [  
{  
“SerialNumber”: “600609”,  
“measurements”: {  
“LowFrequency”: {  
“x”: {  
“unit”: “G”  
},  
“y”: {  
“unit”: “G”  
},  
“z”: {  
“unit”: “G”  
},  
},  
}  
}  
]  
}  
],  
}

---

<div class="post-metadata">

**Author:** ![dbraus](https://avatars.discourse-cdn.com/v4/letter/d/74df32/32.png) [@dbraus](https://community.postman.com/u/dbraus)\
**Post date:** [March 24, 2020, 6:39pm UTC](https://community.postman.com/t/how-to-deal-with-input-json-with-varying-array-lengths-when-reading-from-external-file/11491/2 "2020-03-24T18:39:45Z")

</div>

I realize now that I should simplify this question:

Can nested JSON objects be passed in from an external file at all?

---

<div class="post-metadata">

**Author:** ![dbraus](https://avatars.discourse-cdn.com/v4/letter/d/74df32/32.png) [@dbraus](https://community.postman.com/u/dbraus)\
**Post date:** [March 25, 2020, 7:48pm UTC](https://community.postman.com/t/how-to-deal-with-input-json-with-varying-array-lengths-when-reading-from-external-file/11491/3 "2020-03-25T19:48:28Z")

</div>

I figured out the answer to this question: Its the same answer I posted in the following link: [Comparing API response to JSON in an external file](https://community.postman.com/t/comparing-api-response-to-json-in-an-external-file/11490/)

You can pass the entire JSON in, assign it to an environmental variable in the pre-req using pm.iterationData.get , and then call that environmental variable in the body
