# Split Huge Json array into multiple smaller POST

**URL:** <https://community.postman.com/t/split-huge-json-array-into-multiple-smaller-post/9669>\
**Category:** Help Hub\
**Created:** [December 17, 2019, 9:26pm UTC](https://community.postman.com/t/split-huge-json-array-into-multiple-smaller-post/9669 "2019-12-17T21:26:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bug\_nuts](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@bug\_nuts](https://community.postman.com/u/bug_nuts)\
**Post date:** [December 17, 2019, 9:26pm UTC](https://community.postman.com/t/split-huge-json-array-into-multiple-smaller-post/9669/1 "2019-12-17T21:26:33Z")

</div>

I have a Json array that has 25,000 objects and I want to send to an endpoint, unfortunately the endpoint only supports a max for 1000 objects in an array before it fails out.

Is it possible to use a pre-request script to split the array into 25 small POST calls? I know that i could use Runner to POST one object per call, but since the endpoint can accept multiple objects I would like to send a larger bulk of objects to cut down on how long it takes to process in postman.

Any advice would be appreciated!

---

<div class="post-metadata">

**Author:** ![john-paul](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/john-paul/32/919_2.png) [@john-paul](https://community.postman.com/u/john-paul)\
**Post date:** [December 19, 2019, 5:56pm UTC](https://community.postman.com/t/split-huge-json-array-into-multiple-smaller-post/9669/2 "2019-12-19T17:56:38Z")

</div>

Hi @bug_nuts,

Yes, you should be able to do this using pre-request scripts. You’ll just need to use Javascript to grab chunks of the larger object, and format them appropriately. I’d recommend something like the following flow:

1. Store your full array of object in an environment
2. Include a dynamic variable in your request body, such as `{{request_body}}`, which you will set a value for in your pre-request script (this is where you array data will go)
3. In a pre-request script, grab just indexes of the full array you need. Structure this data appropriately for your request, then use `pm.variables.set("request_body",value)` to set the value of your dynamic variable `{{request_body}}`.

1. Keep track of which indexes you’ve already iterated through by storing this information using `pm.environment.set(key,value)`.
2. Loop your request using `postman.setNextRequest()`, until all indexes in your array have been sent.

Hope that helps! Let me know if you need a more concrete example.

---

<div class="post-metadata">

**Author:** ![bug\_nuts](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@bug\_nuts](https://community.postman.com/u/bug_nuts)\
**Post date:** [December 19, 2019, 6:29pm UTC](https://community.postman.com/t/split-huge-json-array-into-multiple-smaller-post/9669/3 "2019-12-19T18:29:15Z")

</div>

Thank you so much! I got close , but didnt understand I could just put the full array into an environment variable.

I’ll give it a shot and let you know if I run into any issues.

---

<div class="post-metadata">

**Author:** ![john-paul](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/john-paul/32/919_2.png) [@john-paul](https://community.postman.com/u/john-paul)\
**Post date:** [December 19, 2019, 6:57pm UTC](https://community.postman.com/t/split-huge-json-array-into-multiple-smaller-post/9669/4 "2019-12-19T18:57:29Z")

</div>

Cool! Just know the array in the environment will be stored as a string, so use JSON.parse() to reconstitute it. 🙂

---

<div class="post-metadata">

**Author:** ![mmsohel](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@mmsohel](https://community.postman.com/u/mmsohel)\
**Post date:** [September 16, 2022, 10:36am UTC](https://community.postman.com/t/split-huge-json-array-into-multiple-smaller-post/9669/5 "2022-09-16T10:36:29Z")

</div>

Hi @john-paul,  
I am a newbie and learning Postman. I have a similar query that @bug_nuts has logged a while ago.  
I have a large JSON array string that I have stored in an environment variable. This JSON array has over 1000 objects. However, I want to split the array and each small array will have 50 objects. Then, I want to pass each small array to ‘request\_body’ in a loop until the full POST call is completed.  
I would appreciate it if you could give me an example.  
Kind regards
