# JSON object not Updating

**URL:** <https://community.postman.com/t/json-object-not-updating/36014>\
**Category:** Help Hub\
**Tags:** pre-request-script\
**Created:** [June 7, 2022, 7:04pm UTC](https://community.postman.com/t/json-object-not-updating/36014 "2022-06-07T19:04:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scot](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/scot/32/12059_2.png) [@Scot](https://community.postman.com/u/Scot)\
**Post date:** [June 7, 2022, 7:04pm UTC](https://community.postman.com/t/json-object-not-updating/36014/1 "2022-06-07T19:04:40Z")

</div>

Hello! I am trying to set up a pre-request script for a PUT call that gets a JSON response, then I am trying to change a value of the json object, and I am not sure what I might be doing wrong.

Image below of function I am having trouble with. responseBody.fields[i].properties.description is keeping its old value rather than updating to “THIS IS A TEST”.

Does anybody have any ideas for me? 🙂 Thanks!

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/d/d388aa10bdf27abbf5bab76a5232b6bdea0b30fe.jpeg)

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 7, 2022, 11:55pm UTC](https://community.postman.com/t/json-object-not-updating/36014/2 "2022-06-07T23:55:43Z")

</div>

> [@Scot](#):
>
> I am trying to set up a pre-request script for a PUT call that gets a JSON response

Hi @Scot

How are you getting the JSON if your script is in a pre-req? Wouldn’t you have to execute the call first and then alter the JSON response in the ‘test’ tab?

Trying to understand what you’re trying to do, could you potentially copy in the response text and full pre-req script?

---

<div class="post-metadata">

**Author:** ![Scot](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/scot/32/12059_2.png) [@Scot](https://community.postman.com/u/Scot)\
**Post date:** [June 10, 2022, 6:41pm UTC](https://community.postman.com/t/json-object-not-updating/36014/3 "2022-06-10T18:41:18Z")

</div>

Hey @w4dd325 thanks for replying. Yea, that’s on me, I didn’t provide full context. I am running a GET call in the same pre-req script just before this:

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/b/b99444169fc31b3619b41986a1dc77a3f9dde264.jpeg)

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 10, 2022, 10:56pm UTC](https://community.postman.com/t/json-object-not-updating/36014/4 "2022-06-10T22:56:46Z")

</div>

I’m not going to claim to know a lot about JS, it’s pretty new to me…

But I have been playing around with your code… And I think I have identified the issue… here is my theory;

I think this is a contradicting statement…

```auto
for (var i=0; responseBody.fields[i].ref !== ref; i++) {
        if (responseBody.fields[i].ref === ref) {

```

I read this as;  
loop through each item while _**responseBody.fields[i].ref**_ is **NOT** equal to “dynamicDesc”.

Inside that for loop you then have;  
If _**responseBody.fields[i].ref**_ **IS** equal to “dynamicDesc”.

The ‘if’ can’t be triggered right? because the for loop will stop when they become equal…

However, If I change the for loop to .length

`for (var i=0; responseBody.fields.length; i++)`

It appears to do what you are describing.

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/4/4f86dbb940ca95fb8017ab6d3b8ff6c8a054ae49.png)
