# Is it possible to manipulate the JSON via script before sending the request

**URL:** <https://community.postman.com/t/is-it-possible-to-manipulate-the-json-via-script-before-sending-the-request/43074>\
**Category:** Help Hub\
**Created:** [January 20, 2023, 3:29am UTC](https://community.postman.com/t/is-it-possible-to-manipulate-the-json-via-script-before-sending-the-request/43074 "2023-01-20T03:29:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![postmanben1386](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@postmanben1386](https://community.postman.com/u/postmanben1386)\
**Post date:** [January 20, 2023, 3:29am UTC](https://community.postman.com/t/is-it-possible-to-manipulate-the-json-via-script-before-sending-the-request/43074/1 "2023-01-20T03:29:28Z")

</div>

Hi all,

I have a postman request and was able to use a CSV input data to supply variable values to run. This is great where we just want to run with different values for some key in the JSON. However, for my test cases there are scenarios where some child element should NOT be there. In this case it’s not just a matter of substituting a variable with a value but rather the entire “key” : “value” entry should be omitted.

How do I achieve this? Can this be done via the Pre-request Script or some other tricks?

Thanks everyone in advance.

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [January 20, 2023, 4:04am UTC](https://community.postman.com/t/is-it-possible-to-manipulate-the-json-via-script-before-sending-the-request/43074/2 "2023-01-20T04:04:47Z")

</div>

Yes in pre request u can modify request body as pm.request.body= 🥳

---

<div class="post-metadata">

**Author:** ![postmanben1386](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@postmanben1386](https://community.postman.com/u/postmanben1386)\
**Post date:** [January 20, 2023, 4:11am UTC](https://community.postman.com/t/is-it-possible-to-manipulate-the-json-via-script-before-sending-the-request/43074/3 "2023-01-20T04:11:00Z")

</div>

Thank you! I will explore this.

---

<div class="post-metadata">

**Author:** ![postmanben1386](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@postmanben1386](https://community.postman.com/u/postmanben1386)\
**Post date:** [January 20, 2023, 4:53am UTC](https://community.postman.com/t/is-it-possible-to-manipulate-the-json-via-script-before-sending-the-request/43074/4 "2023-01-20T04:53:06Z")

</div>

If I use newman would I be able to read a JSON (which is to be manipulated) from the local drive as well as the data (CSV) file?

---

<div class="post-metadata">

**Author:** ![postmanben1386](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@postmanben1386](https://community.postman.com/u/postmanben1386)\
**Post date:** [January 22, 2023, 11:27pm UTC](https://community.postman.com/t/is-it-possible-to-manipulate-the-json-via-script-before-sending-the-request/43074/5 "2023-01-22T23:27:10Z")

</div>

OK, so I manipulated and updated the request body as below:

let requestData = JSON.parse(pm.request.body);

some manipulation codes here …

pm.request.body = JSON.stringify(requestData);

It seems that doing so automatically changed the content-type in the header to “text/plain”.

How do I change the content type in the header back to “application/json”?

---

<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:** [January 23, 2023, 11:48am UTC](https://community.postman.com/t/is-it-possible-to-manipulate-the-json-via-script-before-sending-the-request/43074/6 "2023-01-23T11:48:29Z")

</div>

You need to parse and update the raw element of the body, which will leave everything else including the header intact.

```auto
const body = JSON.parse(pm.request.body.raw);
// some manipulation here.
pm.request.body.raw = body;

```
