Hi there!
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
}
]
What Postman sends:
{"id":"33252f12-80ca-4ab1-a5b8-209de4cc501c","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"}]}