# What's the best way to manipulate part of the response before sending it in a new request?

**URL:** <https://community.postman.com/t/whats-the-best-way-to-manipulate-part-of-the-response-before-sending-it-in-a-new-request/33588>\
**Category:** Help Hub\
**Tags:** tests, json\
**Created:** [March 17, 2022, 11:32am UTC](https://community.postman.com/t/whats-the-best-way-to-manipulate-part-of-the-response-before-sending-it-in-a-new-request/33588 "2022-03-17T11:32:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhijeet](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@abhijeet](https://community.postman.com/u/abhijeet)\
**Post date:** [March 17, 2022, 11:32am UTC](https://community.postman.com/t/whats-the-best-way-to-manipulate-part-of-the-response-before-sending-it-in-a-new-request/33588/1 "2022-03-17T11:32:22Z")

</div>

Hi,

I have a JSON that I get from the response of request1 and I want to manipulate the content of it and send it as a new request: request2.

Here’s how my sample JSON looks like:

```auto
 {
           "date": "",
          "vendor_name": "",
          "vendor_id": "", 
          "lines": [
                {
                    "line_description": "demo - test",
                    "line_detail": {
                        "ids": {
                            "abc_id": "34",
                            "def_id": "31201",
                            "account_id": "31201",
                            "account_name": "Dell"
                        },
                        "class": {}
                    },
                    "detail_type": "line_detail",
                    "line_id": "1",
                    "amount": 122.21,
                    "line_type": "",
                }
            ],
}

```

In my request I need to send one change at a time in the Lines array separately. I can store the Lines array in an environment variable but I want to first replace only the “ **line\_description** ” value in that response while keeping the rest of the json the same and then in the third request (request3) with that value and modify the existing value for “ **abc\_id** ”, and so on.

I was thinking of converting the response to XML and then manipulate the response but I learned that postman doesn’t support JSON to XML out of the box. So wondering if there’s a better way of handling it?

Note that I don’t have a predefined value I can use, I want to manipulate the value from existing response JSON and update one of the values before sending it. The question I have is more about how to manipulate the JSON than chaining the requests.

---

<div class="post-metadata">

**Author:** ![sean.keegan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/sean.keegan/32/6353_2.png) [@sean.keegan](https://community.postman.com/u/sean.keegan)\
**Post date:** [March 17, 2022, 2:48pm UTC](https://community.postman.com/t/whats-the-best-way-to-manipulate-part-of-the-response-before-sending-it-in-a-new-request/33588/2 "2022-03-17T14:48:32Z")

</div>

Hi @abhijeet ,

I think you may be able to do something like storing the response in the Postman sandbox, changing the value you want, and then saving it as a variable to use in subsequent requests. For example, if that’s the response you’re getting from an API call, you can write in the Tests tab:  
`var jsonResponse = pm.response.json();`

Now you can do whatever you want with your `jsonResponse` object, including changing key values, removing fields, etc. From there, you can stringify that object and save it as a collection variable. Next, in the pre request script of your next request, you can use `pm.collectionVariables.get('variable_name')`, parse the stringified version of the variable, and you’ll have a JavaScript object you can work with and use the values of.

If it’s easier to see a hands on example, check out [this public workspace](https://www.postman.com/devrel/workspace/helpful-answer-public-workspace/overview) I created that has two basic requests that goes through this workflow. You can modify it to your use case. Hopefully this helps!

---

<div class="post-metadata">

**Author:** ![abhijeet](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@abhijeet](https://community.postman.com/u/abhijeet)\
**Post date:** [March 18, 2022, 4:20pm UTC](https://community.postman.com/t/whats-the-best-way-to-manipulate-part-of-the-response-before-sending-it-in-a-new-request/33588/3 "2022-03-18T16:20:05Z")

</div>

Thanks Sean! That does the job for me 👍

---

<div class="post-metadata">

**Author:** ![sean.keegan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/sean.keegan/32/6353_2.png) [@sean.keegan](https://community.postman.com/u/sean.keegan)\
**Post date:** [March 18, 2022, 5:34pm UTC](https://community.postman.com/t/whats-the-best-way-to-manipulate-part-of-the-response-before-sending-it-in-a-new-request/33588/4 "2022-03-18T17:34:35Z")

</div>

Great news! I’m glad it was helpful 🙂

Happy API testing!

---

<div class="post-metadata">

**Author:** ![jdjady1990](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jdjady1990](https://community.postman.com/u/jdjady1990)\
**Post date:** [October 13, 2022, 4:56pm UTC](https://community.postman.com/t/whats-the-best-way-to-manipulate-part-of-the-response-before-sending-it-in-a-new-request/33588/5 "2022-10-13T16:56:00Z")

</div>

Hi, the link you provided here doesn’t work [Postman](https://www.postman.com/devrel/workspace/helpful-answer-public-workspace/overview)

---

<div class="post-metadata">

**Author:** ![priyankab10](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@priyankab10](https://community.postman.com/u/priyankab10)\
**Post date:** [February 2, 2024, 8:38am UTC](https://community.postman.com/t/whats-the-best-way-to-manipulate-part-of-the-response-before-sending-it-in-a-new-request/33588/6 "2024-02-02T08:38:09Z")

</div>

Hey @sean.keegan , the link you provided does not work. really need help on this one. Can you send the proper link to the workspace

---

<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:** [February 2, 2024, 10:45am UTC](https://community.postman.com/t/whats-the-best-way-to-manipulate-part-of-the-response-before-sending-it-in-a-new-request/33588/7 "2024-02-02T10:45:37Z")

</div>

@priyankab10

This thread is nearly two years old.

Please create a new topic, detailing what you need, including screenshots and example responses, and I’m sure we will be able to provide updated information on how to do this.

The short form is that you will need to store the body as a variable. (Collection or Environment). You can either retrieve the existing body, make amendments and then resave (or you can use another variable if you have one in the correct format.

You can then use a pre-request script for the next request to overwrite the body using something similar to the following.

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

```

---

<div class="post-metadata">

**Author:** ![priyankab10](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@priyankab10](https://community.postman.com/u/priyankab10)\
**Post date:** [February 2, 2024, 11:26am UTC](https://community.postman.com/t/whats-the-best-way-to-manipulate-part-of-the-response-before-sending-it-in-a-new-request/33588/8 "2024-02-02T11:26:24Z")

</div>

i found out what i wanted …[Postman](https://www.postman.com/postman/workspace/postman-answers/collection/13455110-9b25e885-45fc-402c-89bf-251b15962711) this link was helpful. Thanks
