First of all, you haven’t use the preformatted text option so everything is aligned to the left which is hard to read.
Please re-post using the preformatted text, so its easier to see objects within object, etc. It helps a lot when targeting elements. It also helps if I’m going to cut and paste it into Postman. I’m not going to copy\paste, and then spend another five minutes re-formatting the code so its readable. If you don’t use the preformatted text option, then all of the quotes gets transposed and have to changed back.
I am assuming here that you want to take an element from the 1st response to use in the 2nd request, but re-reading your original question I’m actually unsure if this is what you want.
So can I please ask again for you to be as specific as possible.
What key specifically in the request body do you want to update?
And which value from the response do you want to use to update the key?
Thanks for your reply, I am trying to use the response from one request as body of another request in a collection but before using the the response, I want to edit it as below in Pre-request Script of 2nd request: -
Your problem is that context is an object within a string, instead of a straight up object.
const response = {
"basketAction": "AddAfterConfig",
"productConfig": {
"offerDetails": {
"offer": {
"addtocart": {
"rest": {
"params": {
"context": '{"AFFILIATES_ID":"Affiliate"}'
}
}
}
}
}
}
}
// console log initial response
console.log(response);
// context is an object in a string
// so we will parse it to an object.
let context = JSON.parse(response.productConfig.offerDetails.offer.addtocart.rest.params.context);
// and console log it.
console.log(context);
// we can now update the elements directly.
context.AFFILIATES_ID = "Hello";
console.log(context);
// before updating the context in the intial response - remembering to stringify it.
response.productConfig.offerDetails.offer.addtocart.rest.params.context = JSON.stringify(context);
console.log(response);