# Subtract a value from a response

**URL:** <https://community.postman.com/t/subtract-a-value-from-a-response/29197>\
**Category:** Help Hub\
**Created:** [October 28, 2021, 2:38pm UTC](https://community.postman.com/t/subtract-a-value-from-a-response/29197 "2021-10-28T14:38:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![parsy2](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@parsy2](https://community.postman.com/u/parsy2)\
**Post date:** [October 28, 2021, 2:38pm UTC](https://community.postman.com/t/subtract-a-value-from-a-response/29197/1 "2021-10-28T14:38:10Z")

</div>

Can someone please help me, I have a response that has a value=1000 I want to take it and subtract 100 for example so: 1000-100=900 and set it as a variable?

Maybe something like:

```auto
var jsonData = JSON.parse(responseBody);
pm.environment.set("NewValue", jsonData.data.(oldvalue-100));

```

---

<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:** [October 28, 2021, 7:33pm UTC](https://community.postman.com/t/subtract-a-value-from-a-response/29197/2 "2021-10-28T19:33:42Z")

</div>

Hey @parsy2 👋

Can you share an example of the response body please?

It will make it easier for someone to offer a solution.

---

<div class="post-metadata">

**Author:** ![poojamistry22](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@poojamistry22](https://community.postman.com/u/poojamistry22)\
**Post date:** [January 6, 2022, 2:21am UTC](https://community.postman.com/t/subtract-a-value-from-a-response/29197/3 "2022-01-06T02:21:21Z")

</div>

Hi @[parsy2](https://community.postman.com/u/parsy2) and @[dannydainton](https://community.postman.com/u/dannydainton) 👋🏽

I agree that it may be easier if we get an example of your response body, however in the meantime let me show you an example of how you could go about doing this using [Valentin Despa](https://www.youtube.com/watch?v=JzpFsrZnNDo) ‘s API Documentation examples.

I will be playing with this Order Pizza API

> **Summary**
>
> This text will be hidden

: [Swagger UI](http://pizzeria-valentino.herokuapp.com/api/ui/#!/Orders/orders_read_all)

The response body for this Get Request is the following :

```
[
    {
        "Crust": "NORMAL",
        "Flavor": "BEEF-NORMAL",
        "Order_ID": 1,
        "Size": "M",
        "Table_No": 1,
        "Timestamp": "2019-12-03T18:21:08.669365"
    },
    {
        "Crust": "THIN",
        "Flavor": "CHEESE",
        "Order_ID": 2,
        "Size": "S",
        "Table_No": 5,
        "Timestamp": "2019-12-03T18:21:08.708470"
    },
    {
        "Crust": "NORMAL",
        "Flavor": "CHICKEN-FAJITA",
        "Order_ID": 3,
        "Size": "L",
        "Table_No": 3,
        "Timestamp": "2019-12-03T18:21:08.710006"
    }
]

```

This is how I would go about parsing this response body, subtracting a number and adding it to an environment variable.

The first thing you would need to do is parse the correct object that you are interested in by index. In my case, I am interested in the “Table\_No” value in index 1, which is a value of 5.

```
var jsonData = JSON.parse(responseBody);
var x = jsonData[1].Table_No; 

```

Once I have that value, I can then go ahead and subtract it by whatever and then finally set the environment variable

```
var y = x - 2;
pm.environment.set("NewValue", y);

```

I have this all in a test to show you the result. Here I am expecting a value of 3.

![](https://paper-attachments.dropbox.com/s_4D1038CC1673C967FCD631DD5893354ED5E448061323061465D6C134CEF86F7C_1641434991572_Screen+Shot+2022-01-05+at+9.09.48+PM.png)

As you can see, I have also created an environment variable, that takes the subtracted value when you send the request.

![](https://paper-attachments.dropbox.com/s_4D1038CC1673C967FCD631DD5893354ED5E448061323061465D6C134CEF86F7C_1641435157058_Screen+Shot+2022-01-05+at+9.12.33+PM.png)

I hope this example helps you see how you can go about doing something similar with your use case.

If you are interested in condensing the script this would work as well:

```
var jsonData = JSON.parse(responseBody);
pm.environment.set("NewValue", (jsonData[1].Table_No)-2);

```

![](https://paper-attachments.dropbox.com/s_4D1038CC1673C967FCD631DD5893354ED5E448061323061465D6C134CEF86F7C_1641435430621_Screen+Shot+2022-01-05+at+9.17.07+PM.png)
