JSON object not Updating

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? :slight_smile: Thanks!

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?

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:

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…

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.