I want to loop over a JSON array of objects and use each object directly as body, and send it as it is.
I upload my JSON fil to the runner and add the request to execute. The runner identifies the number of iterateion correctly. I set my request’s body to raw
and JSON
and clear it. Then a add this pre-script:
let currentData = pm.iterationData.toJSON();
console.log(“Sending request body:”, JSON.stringify(currentData));
pm.request.body.raw = JSON.stringify(currentData);
But when I start a run, instead of sending my data, Postman send its serialized version.
How to prevent this behaviour and send just the data from the JSON file?
My data:
[
{
"title": "Project A Title",
"role": "Project A Role",
"from": "1970-01",
"to": "1970-12",
"tasks": "Project A Tasks",
"tools": null,
"skills": [
"Java",
"Python",
"PHP"
],
"customerName": "Project A Customer",
"displayCustomerName": true,
"location": null,
"businessDepartment": null,
"businessBranch": null,
"contractType": null,
"contractHoursPercentage": null,
"hourlyRate": {
"paymentRate": null,
"paymentCurrency": "EUR"
},
"selectedDirektProject": null
},
{
"title": "Project B Title",
"role": "Project B Role",
"from": "1971-01",
"to": "1971-12",
"tasks": "Project B Tasks",
"tools": null,
"skills": [
"Ruby",
"Kotlin",
"TypeScript"
],
"customerName": "Project B Customer",
"displayCustomerName": true,
"location": null,
"businessDepartment": null,
"businessBranch": null,
"contractType": null,
"contractHoursPercentage": null,
"hourlyRate": {
"paymentRate": null,
"paymentCurrency": "EUR"
},
"selectedDirektProject": null
}
]
What Postman sends:
Iteration 1:
{
"id": "e32d5e83-bd44-4782-9b59-0f8de6bb7f0d",
"values": [
{
"type": "any",
"value": "Project A Title",
"key": "title"
},
{
"type": "any",
"value": "Project A Role",
"key": "role"
},
{
"type": "any",
"value": "1970-01",
"key": "from"
},
{
"type": "any",
"value": "1970-12",
"key": "to"
},
{
"type": "any",
"value": "Project A Tasks",
"key": "tasks"
},
{
"type": "any",
"value": null,
"key": "tools"
},
{
"type": "any",
"value": [
"Java",
"Python",
"PHP"
],
"key": "skills"
},
{
"type": "any",
"value": "Project A Customer",
"key": "customerName"
},
{
"type": "any",
"value": true,
"key": "displayCustomerName"
},
{
"type": "any",
"value": null,
"key": "location"
},
{
"type": "any",
"value": null,
"key": "businessDepartment"
},
{
"type": "any",
"value": null,
"key": "businessBranch"
},
{
"type": "any",
"value": null,
"key": "contractType"
},
{
"type": "any",
"value": null,
"key": "contractHoursPercentage"
},
{
"type": "any",
"value": {
"paymentRate": null,
"paymentCurrency": "EUR"
},
"key": "hourlyRate"
},
{
"type": "any",
"value": null,
"key": "selectedDirektProject"
}
]
}
Iteration 2:
{
"id": "6309e0a7-53e9-4286-a5fd-9da50dc866c1",
"values": [
{
"type": "any",
"value": "Project B Title",
"key": "title"
},
{
"type": "any",
"value": "Project B Role",
"key": "role"
},
{
"type": "any",
"value": "1971-01",
"key": "from"
},
{
"type": "any",
"value": "1971-12",
"key": "to"
},
{
"type": "any",
"value": "Project B Tasks",
"key": "tasks"
},
{
"type": "any",
"value": null,
"key": "tools"
},
{
"type": "any",
"value": [
"Ruby",
"Kotlin",
"TypeScript"
],
"key": "skills"
},
{
"type": "any",
"value": "Project B Customer",
"key": "customerName"
},
{
"type": "any",
"value": true,
"key": "displayCustomerName"
},
{
"type": "any",
"value": null,
"key": "location"
},
{
"type": "any",
"value": null,
"key": "businessDepartment"
},
{
"type": "any",
"value": null,
"key": "businessBranch"
},
{
"type": "any",
"value": null,
"key": "contractType"
},
{
"type": "any",
"value": null,
"key": "contractHoursPercentage"
},
{
"type": "any",
"value": {
"paymentRate": null,
"paymentCurrency": "EUR"
},
"key": "hourlyRate"
},
{
"type": "any",
"value": null,
"key": "selectedDirektProject"
}
]
}