[GH-ISSUE #1024] Scripts that assign the JSON response.body to true fail #1019

Open
opened 2026-03-03 19:23:49 +03:00 by kerem · 4 comments
Owner

Originally created by @BenTilbrook on GitHub (Oct 12, 2021).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/1024

Originally assigned to: @NghiaTranUIT on GitHub.

Scripts that assign the response.body to true fail with an error (see below for error details).

If I wrap the true literal in a JSON object, it works. However, true is valid JSON, and many JSON APIs return only boolean literals.

Here's the full script I'm using:

function onResponse(context, url, request, response) {
  response.body = true;
  response.headers["Content-Type"] = "application/json"
  response.statusCode = 200
  return response;
}

Proxyman version

2.33.0 (23300)

macOS Version

11.6 (20G165)

Steps to reproduce

  1. Create a script
  2. Enter the script content above
  3. Save and activate it
  4. Exercise the script by requesting the endpoint

Expected behavior

The response body is true

Actual behavior

An error is reported:

❌Error: Invalid Body JSON Object. Please verify the body is a valid JSON. (Content-Type=application/json)
Originally created by @BenTilbrook on GitHub (Oct 12, 2021). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/1024 Originally assigned to: @NghiaTranUIT on GitHub. Scripts that assign the `response.body` to `true` fail with an error (see below for error details). If I wrap the `true` literal in a JSON object, it works. However, `true` is valid JSON, and many JSON APIs return only boolean literals. Here's the full script I'm using: ```javascript function onResponse(context, url, request, response) { response.body = true; response.headers["Content-Type"] = "application/json" response.statusCode = 200 return response; } ``` ### Proxyman version `2.33.0 (23300)` ### macOS Version `11.6 (20G165)` ### Steps to reproduce 1. Create a script 2. Enter the script content above 3. Save and activate it 4. Exercise the script by requesting the endpoint ### Expected behavior The response body is `true` ### Actual behavior An error is reported: ``` ❌Error: Invalid Body JSON Object. Please verify the body is a valid JSON. (Content-Type=application/json) ```
Author
Owner

@NghiaTranUIT commented on GitHub (Oct 12, 2021):

I wasn't aware that true/false could be a valid JSON object 🙀

I'm fixing it and send you a beta build soon 👍

<!-- gh-comment-id:940581214 --> @NghiaTranUIT commented on GitHub (Oct 12, 2021): I wasn't aware that true/false could be a valid JSON object 🙀 I'm fixing it and send you a beta build soon 👍
Author
Owner

@NghiaTranUIT commented on GitHub (Oct 12, 2021):

Hey @BenTilbrook please try this beta buid: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.33.0_Fix_Primitive_JSON_Scripting.dmg

You can use primitive json 👍

<!-- gh-comment-id:940679601 --> @NghiaTranUIT commented on GitHub (Oct 12, 2021): Hey @BenTilbrook please try this beta buid: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.33.0_Fix_Primitive_JSON_Scripting.dmg You can use primitive json 👍
Author
Owner

@BenTilbrook commented on GitHub (Oct 14, 2021):

@NghiaTranUIT I can confirm this fixes the problem. Thanks for the super quick response!

<!-- gh-comment-id:942875101 --> @BenTilbrook commented on GitHub (Oct 14, 2021): @NghiaTranUIT I can confirm this fixes the problem. Thanks for the super quick response!
Author
Owner

@thientan21 commented on GitHub (Oct 26, 2021):

@BenTilbrook @NghiaTranUIT you guys are absolutely amazing 😊

<!-- gh-comment-id:951575905 --> @thientan21 commented on GitHub (Oct 26, 2021): @BenTilbrook @NghiaTranUIT you guys are absolutely amazing 😊
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#1019
No description provided.