0

I want to edit an outbound payload using set-body in this way:

{"link": "http://localhost:7071/api"} to {"link":""} <- some other link

I have tried this but there is no change in outbound:

JObject inBody = context.Response.Body.As<JObject>(); 
string str = inBody.ToString();
var item = JObject.Parse("{ 'link': 'http://localhost:7071/api}");
item["link"] = "https://randomlink/269";
return str; 
Aadhar
  • 57
  • 7
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 28 '21 at 20:01

1 Answers1

0

To explain why your code does not work:

JObject inBody = context.Response.Body.As<JObject>(); //Request
payload has been parsed and stored in `inBody` variable.
string str = inBody.ToString(); //`inBody` converted to string and stored in `str` variable.
var item = JObject.Parse("{ 'link': 'http://localhost:7071/api}"); //Some other JSON parsed and stored in `item` variable
item["link"] = "https://randomlink/269"; //`item` variable updated with new value
return str; //Returning `str` variable as new body value

You never actually change value of str to produce new body. Try:

JObject inBody = context.Response.Body.As<JObject>(); 
inBody["link"] = "https://randomlink/269";
return inBody.ToString();
Vitaliy Kurokhtin
  • 7,205
  • 1
  • 19
  • 18