# How to use single json file with multiple diff payloads

**URL:** <https://community.postman.com/t/how-to-use-single-json-file-with-multiple-diff-payloads/51100>\
**Category:** Help Hub\
**Tags:** jsondatafile, collection-runner\
**Created:** [August 29, 2023, 8:12am UTC](https://community.postman.com/t/how-to-use-single-json-file-with-multiple-diff-payloads/51100 "2023-08-29T08:12:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![18fms](https://avatars.discourse-cdn.com/v4/letter/1/5f9b8f/32.png) [@18fms](https://community.postman.com/u/18fms)\
**Post date:** [August 29, 2023, 8:12am UTC](https://community.postman.com/t/how-to-use-single-json-file-with-multiple-diff-payloads/51100/1 "2023-08-29T08:12:18Z")

</div>

I have a JSON file containing two payloads for different endpoints: one for POST and the other for PUT requests. When I run the JSON file through the collection runner, I encounter an issue.

If I set the iteration to 2, it results in duplicate data being created in the database. On the other hand, if I set the iteration to 1, only the first request is sent.

This is how my json file looks like:

```json
[
    {
        "endpoint": "/save",
        "method":"POST",
        "A": 2,
        "B": "item 2", 
    },
   {
       "endpoint": "/update",
       "method":"PUT",
       "id": {{id}},
       "A": 2,
       "B": "update1",
   }    
]

```

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [August 29, 2023, 11:49am UTC](https://community.postman.com/t/how-to-use-single-json-file-with-multiple-diff-payloads/51100/2 "2023-08-29T11:49:42Z")

</div>

You current have an array with two records in it.

Therefore the collection runner will have two iterations.

You need to store the array in an object like following.

```auto
{
    "testData": [
        {
            "endpoint": "/save",
            "method": "POST",
            "A": 2,
            "B": "item 2"
        },
        {
            "endpoint": "/update",
            "method": "PUT",
            "id": "123",
            "A": 2,
            "B": "update1"
        }
    ]
}

```

This will then run once (for the testData object).

You can then access the elements in the array by its array index.

```auto
console.log(data.testData[0].endpoint); // save
console.log(data.testData[1].endpoint); // update

```

Or consider, not having an array at all and structuring the JSON similar to the following.

```auto
{
    "post": {
        "endpoint": "/save",
        "A": 2,
        "B": "item 2"
    },
    "put": {
        "endpoint": "/update",
        "id": "123",
        "A": 2,
        "B": "update1"
    }
}

```

```auto
console.log(data.post.endpoint); // save
console.log(data.put.endpoint); // update

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [November 27, 2023, 11:50am UTC](https://community.postman.com/t/how-to-use-single-json-file-with-multiple-diff-payloads/51100/3 "2023-11-27T11:50:41Z")

</div>

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