Incorrect parsing of JSON file when using Runner

I am attempting to submit a JSON-formatted array of JSON payloads for sequential processing using the Runner. However, the logs show a different Request Payload than the one I am trying to submit.

A genericized example of my input file contents is this (I wish to process each policyInformation element in a separate request):

[
    {
        "policyInformation": {
            "policyNumber": "policyNumber",
            "producer": {
                "type": "type",
                "producerNumber": "producerNumber"
            }
        },
        "driverInformation": {
            "drivers": [
                {
                    "firstName": "firstName",
                    "middleName": "middleName",
                    "lastName": "lastName"
                },
                {
                    "firstName": "firstName",
                    "middleName": "middleName",
                    "lastName": "lastName"
                }
            ]
        }
    },
    {
        "policyInformation": {
            "policyNumber": "policyNumber",
            "producer": {
                "type": "type",
                "producerNumber": "producerNumber"
            }
        },
        "driverInformation": {
            "drivers": [
                {
                    "firstName": "firstName",
                    "middleName": "middleName",
                    "lastName": "lastName"
                }
            ]
        },
        "transactionType": "transactionType"
    }
]

I am using a variable as my request body:

This is my pre-request script (at the request level):

When i select the file postman does recognize the 2 iterations:

My requests are failing due to invalid payload. The logged payload restructured from what I am trying to send. This is the logged payload:

{
    "id": "c100a6a3-8f25-4103-8e2a-093f8440d185",
    "values": [
        {
            "type": "any",
            "value": {
                "policyNumber": "policyNumber",
                "producer": {
                    "type": "type",
                    "producerNumber": "producerNumber"
                }
            },
            "key": "policyInformation"
        },
        {
            "type": "any",
            "value": {
                "drivers": [
                    {
                        "firstName": "firstName",
                        "middleName": "middleName",
                        "lastName": "lastName"
                    },
                    {
                        "firstName": "firstName",
                        "middleName": "middleName",
                        "lastName": "lastName"
                    }
                ]
            },
            "key": "driverInformation"
        }
    ]
}

When you retrieve the current iteration, it should be toObject(), not toJSON().

let currentIteration = pm.iterationData.toObject();
console.log(currentIteration);
pm.environment.set("payload", JSON.stringify(currentIteration));
// pm.request.body.raw = JSON.stringify(currentIteration); // option 2
1 Like

This worked. Thank you!