# Using 1 json file with multiple arrays as input for different requests

**URL:** <https://community.postman.com/t/using-1-json-file-with-multiple-arrays-as-input-for-different-requests/48375>\
**Category:** Help Hub\
**Tags:** json, jsondatafile\
**Created:** [June 9, 2023, 3:32pm UTC](https://community.postman.com/t/using-1-json-file-with-multiple-arrays-as-input-for-different-requests/48375 "2023-06-09T15:32:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![clauspaludanatp](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@clauspaludanatp](https://community.postman.com/u/clauspaludanatp)\
**Post date:** [June 9, 2023, 3:32pm UTC](https://community.postman.com/t/using-1-json-file-with-multiple-arrays-as-input-for-different-requests/48375/1 "2023-06-09T15:32:00Z")

</div>

I have a collection with multiple post requests (create account, create address etc.) and a json file as input that looks like this:

## Json data file

```auto
{
    "testdata": {
        "accountlist": [
            {
                "bankname": "BARCLAYS BANK UK PLC",
                "accountnumber": "00004005000"
            },
            {
                "bankname": "Bank of America",
                "accountnumber": "00004005001"
            },
            {
                "bankname": "Citigroup",
                "accountnumber": "00004005002"
            },
            {
                "bankname": "Wells Fargo",
                "accountnumber": "00004005003"
            },
            {
                "bankname": "U.S. Bancorp",
                "accountnumber": "00004005004"
            },
            {
                "bankname": "PNC Financial Services",
                "accountnumber": "00004005005"
            }
        ],
        "adresslist": [
            {
                "city": "Edinburg",
                "street": "14 Nile Grove"
            },
            {
                "city": "Copenhagen",
                "street": "Frederiksborggade 12"
            },
            {
                "city": "London",
                "street": "Piccadilly 421"
            }
        ]
    }
}

```

## POST Create Account body

```auto
{
    "bankname": "{{bankname}}",
    "accountnumber": "{{accountnumber}}"
}

```

## POST Create Address body

```auto
{
    "city": "{{city}}",
    "street": "{{street}}"
}

```

How can I get the testdata.accountlist array into the **POST Create Account** as input for each iteration and the testdata.addresslist into the **POST Create Address** as input for each iteration?

---

<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:** [June 12, 2023, 9:34am UTC](https://community.postman.com/t/using-1-json-file-with-multiple-arrays-as-input-for-different-requests/48375/2 "2023-06-12T09:34:36Z")

</div>

My recommendation would be to transform your test data before it gets used in the Postman collection runner, then you wouldn’t need to make any changes and it should run as you currently have variables defined.

Postman requires the JSON to be a straight up array like the following.

```auto
[
	{
		"bankname": "BARCLAYS BANK UK PLC",
		"accountnumber": "00004005000"
	},
	{
		"bankname": "Bank of America",
		"accountnumber": "00004005001"
	},
	{
		"bankname": "Citigroup",
		"accountnumber": "00004005002"
	},
	{
		"bankname": "Wells Fargo",
		"accountnumber": "00004005003"
	},
	{
		"bankname": "U.S. Bancorp",
		"accountnumber": "00004005004"
	},
	{
		"bankname": "PNC Financial Services",
		"accountnumber": "00004005005"
	}
]

```

What I’m not quite getting is that your address list is a completely separate array, so which address should be linked to which bank? You have 6 banks, but 3 addresses.

Personally, I would recommend adding the city and street under the bank name. Keeping the JSON as flat\simple as possible.

If they are completely separate requests, then you will probably need to run these as separate requests in the runner.

You could have the JSON as single string as the only entry in a CSV file, and then use pre-request scripts to retrieve the data and set collection\environment variables for the two different arrays and then create a loop using array shift and setNextRequest but that is a fair bit of code which wouldn’t be needed if the test data was in the correct format. (Just giving that option in case you can’t change the format of the test data).

---

<div class="post-metadata">

**Author:** ![clauspaludanatp](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@clauspaludanatp](https://community.postman.com/u/clauspaludanatp)\
**Post date:** [June 12, 2023, 9:54am UTC](https://community.postman.com/t/using-1-json-file-with-multiple-arrays-as-input-for-different-requests/48375/3 "2023-06-12T09:54:09Z")

</div>

The two lists have nothing to do with each other. The list of banks is input for one request whereas the lists of banks is input for another. So it is indeed the pre-request script required to “fetch” the appropriate array in each request I am looking for.

It would be fairly easy if a specific file could be assigned to each of the different requests rather than only have one file for the entire collection. I could of course make a new collection for each requests, but then the idea of a collection sorta goes away 🙂
