# How to prevent serialization of data when using the runner?

**URL:** <https://community.postman.com/t/how-to-prevent-serialization-of-data-when-using-the-runner/65988>\
**Category:** Help Hub\
**Tags:** runner, collection-runner\
**Created:** [August 12, 2024, 2:20pm UTC](https://community.postman.com/t/how-to-prevent-serialization-of-data-when-using-the-runner/65988 "2024-08-12T14:20:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![automatix](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@automatix](https://community.postman.com/u/automatix)\
**Post date:** [August 12, 2024, 2:20pm UTC](https://community.postman.com/t/how-to-prevent-serialization-of-data-when-using-the-runner/65988/1 "2024-08-12T14:20:41Z")

</div>

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:

```auto
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:

```auto
[
    {
        "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:

```auto
  {"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"}]}

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 12, 2024, 2:43pm UTC](https://community.postman.com/t/how-to-prevent-serialization-of-data-when-using-the-runner/65988/2 "2024-08-12T14:43:58Z")

</div>

Hey @automatix 👋

Welcome to the Postman Community! :postman:

If you have your JSON file structured like this, using the `body` as the key:

```auto
[
	{
		"body": {
			"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
		}
	},
    {
        "body": {
			"title": "Project B Title",
			"role": "Project B Role",
			"from": "1970-01",
			"to": "1970-12",
			"tasks": "Project B Tasks",
			"tools": null,
			"skills": [
				"Java",
				"Python",
				"PHP"
			],
			"customerName": "Project B Customer",
			"displayCustomerName": true,
			"location": null,
			"businessDepartment": null,
			"businessBranch": null,
			"contractType": null,
			"contractHoursPercentage": null,
			"hourlyRate": {
				"paymentRate": null,
				"paymentCurrency": "EUR"
			},
			"selectedDirektProject": null
		}
    }  
]

```

You could add something basic to the pre-request script that sets the value of `payload` at runtime and takes the `body` variable from the JSON datafile:

 ![Screenshot 2024-08-12 at 15.32.13](https://us1.discourse-cdn.com/getpostman/original/3X/2/d/2d6b6c21ce913dec1531f38d3ed37b72f71067de.png)

When the request body contains `{{payload}}` it will use the current iteration data as the request body.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/5/a53f0d9614d35caeab5dcb05a2db595089b9fc19.jpeg)

Is that what you’re trying to do?

---

<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 12, 2024, 4:17pm UTC](https://community.postman.com/t/how-to-prevent-serialization-of-data-when-using-the-runner/65988/4 "2024-08-12T16:17:04Z")

</div>

> [@automatix](#):
>
> `let currentData = pm.iterationData.toJSON();`

I think you just need to change that to toObject().

```auto
let currentData = pm.iterationData.toObject();
console.log("Sending request body:", JSON.stringify(currentData));
pm.request.body.raw = JSON.stringify(currentData);

```

---

<div class="post-metadata">

**Author:** ![automatix](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@automatix](https://community.postman.com/u/automatix)\
**Post date:** [August 14, 2024, 12:41pm UTC](https://community.postman.com/t/how-to-prevent-serialization-of-data-when-using-the-runner/65988/5 "2024-08-14T12:41:47Z")

</div>

Thank you! Just tried this out. The console log looks good. But Postman sends the request with a empty body. that mean `pm.request.body.raw` doesn’t get replaced.

---

<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 14, 2024, 1:02pm UTC](https://community.postman.com/t/how-to-prevent-serialization-of-data-when-using-the-runner/65988/6 "2024-08-14T13:02:09Z")

</div>

I tested this using Postman Echo.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/8/b8d6cee17ed7112fdfc0fbf21d368fb49c80c49e.png)

With this JSON as the data file.

```auto
[
    {
        "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
    }
]

```

The console logs shows the body the request was sent with.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/0/301707d52107639320e21050630fd4d93c6b6372.png)

It is also echoed back from the Postman Echo API. Your request gets echoed back with the data element.

![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/5/952ea880ed54b53c5c728801de39b40c203f9b58.png)

Can you confirm that your body is set to raw\JSON?

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/e/5/e5dc1e232a8f7e4a310a84e9787d9a30409d2fad.png)

---

<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:** [September 13, 2024, 1:02pm UTC](https://community.postman.com/t/how-to-prevent-serialization-of-data-when-using-the-runner/65988/7 "2024-09-13T13:02:28Z")

</div>

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