[GH-ISSUE #891] Modify response body snippet #885

Closed
opened 2026-03-03 19:22:42 +03:00 by kerem · 2 comments
Owner

Originally created by @Floperoid on GitHub (May 15, 2021).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/891

Originally assigned to: @NghiaTranUIT on GitHub.

I want to modify response using Scripting tool. My response is complicated json with nested objects and arrays that looks like that
payload: {
...........
result{
........
value[
.......
"something_i_want_to_change":"123",
.......
]
.........
}
}

How can I replace "123" value to "321"?

Originally created by @Floperoid on GitHub (May 15, 2021). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/891 Originally assigned to: @NghiaTranUIT on GitHub. I want to modify response using Scripting tool. My response is complicated json with nested objects and arrays that looks like that payload: { ........... result{ ........ value[ ....... "something_i_want_to_change":"123", ....... ] ......... } } How can I replace "123" value to "321"?
kerem closed this issue 2026-03-03 19:22:43 +03:00
Author
Owner

@NghiaTranUIT commented on GitHub (May 15, 2021):

Hey @Floperoid, since the body is an Object (Dictionary), so you can access the value as usual. For example:

var body = response.body;

// Change it here
body.payload.result.value[0]. something_i_want_to_change = 123;

// Set it again
response.body = body

If it's too difficult to access a child node from a large JSON, you can export your Response first (Right-click on the Flow -> Export Response Body)

Screen Shot 2021-05-15 at 8 05 17 PM

Then set a response.bodyFilePath as a file path.

function onResponse(context, url, request, response) {
 
  response.headers["Content-Type"] = "image/png";
  response.bodyFilePath = "~/Desktop/image.png";
 
  // Done
  return response;
}

Then, you can easily edit the JSON file with your favorited editor (VS Code or Sublime) 👍

Ref: https://docs.proxyman.io/scripting/snippet-code#map-a-local-file-to-responses-body-like-map-local-tool-proxyman-2-25-0

<!-- gh-comment-id:841656516 --> @NghiaTranUIT commented on GitHub (May 15, 2021): Hey @Floperoid, since the body is an Object (Dictionary), so you can access the value as usual. For example: ```js var body = response.body; // Change it here body.payload.result.value[0]. something_i_want_to_change = 123; // Set it again response.body = body ``` If it's too difficult to access a child node from a large JSON, you can export your Response first (Right-click on the Flow -> Export Response Body) <img width="793" alt="Screen Shot 2021-05-15 at 8 05 17 PM" src="https://user-images.githubusercontent.com/5878421/118362225-dfe70000-b5b8-11eb-8d27-a44937ecc8f6.png"> Then set a `response.bodyFilePath` as a file path. ```js function onResponse(context, url, request, response) { response.headers["Content-Type"] = "image/png"; response.bodyFilePath = "~/Desktop/image.png"; // Done return response; } ``` Then, you can easily edit the JSON file with your favorited editor (VS Code or Sublime) 👍 Ref: https://docs.proxyman.io/scripting/snippet-code#map-a-local-file-to-responses-body-like-map-local-tool-proxyman-2-25-0
Author
Owner

@Floperoid commented on GitHub (May 15, 2021):

Thank you a lot! Turns out It was my inadvertence

<!-- gh-comment-id:841659492 --> @Floperoid commented on GitHub (May 15, 2021): Thank you a lot! Turns out It was my inadvertence
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Proxyman#885
No description provided.