[GH-ISSUE #4957] [bug]: Inconsistent Response Body Type Handling Between Hopp CLI and Hoppscotch Web UI #1874

Open
opened 2026-03-16 22:12:10 +03:00 by kerem · 4 comments
Owner

Originally created by @rajkumar-cp on GitHub (Apr 4, 2025).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/4957

Is there an existing issue for this?

  • I have searched existing issues and this bug hasn't been reported yet

Current behavior

A test script that works successfully when executed from the Hoppscotch web UI fails with a SyntaxError when run from the CLI. The error message indicates that "[object Object]" is not valid JSON.

Steps to reproduce

  1. Execute a test which gives response with an array.
  2. Verify that all tests pass successfully, and the expected values are returned.
  3. Execute the same test script using the Hoppscotch CLI.
  4. Observe the failure and error message.

Logs and Screenshots

<system-err><![CDATA[
      TEST_SCRIPT_ERROR - Script execution failed: SyntaxError: "[object Object]" is not valid JSON]]></system-err>

Environment

Production

Hoppscotch Version

Self-Hosted (v2025.2.3)

Interceptor

Extension - Web App

Browsers Affected

Chrome

Operating System

Windows

Additional Information

Sample response which i am trying to validate

{
"TransactionID": "eb8d75d0",
"ResponseDate": "2025-04-04",
"ResponseTime": "14:01:03",
"Company": [
{
"BusinessPartnerID": "e327c8d1-15bc",
"Error": ""
}
]
}

Sample test which works fine in both web and CLI

// Checking if the status code of the request is 200 (successful)
pw.test("Status code is 200", () => {
pw.expect(pw.response.status).toBe(200);
});

// Checking if the TransactionID is returned in the response
pw.test("TransactionID should not be empty", () => {
pw.expect(pw.response.body.TransactionID).not.toBe("");
});

Sample test which works fine in web and fails in CLI

// Storing the response from the api call as Response, the company's BusinessPartnerID stored as CBPID
const Response = JSON.parse(pw.response.body);
const CBPID = Response.Company[0].BusinessPartnerID;

//Setting the environment variable CBPID with the value received in the response
pw.env.set("CBPID", CBPID);

//Checking if the status code of the request is 200 (successful)
pw.test("Status code is 200", ()=> {
pw.expect(pw.response.status).toBe(200);
});

//Checking if the TransactionID is returned in the response
pw.test("TransactionID should not be empty", () => {
pw.expect(Response.TransactionID).not.toBe("");
});

//Checking if the error field in the response is empty
pw.test("Error should be empty", () => {
pw.expect(Response.Company[0].Error).toBe("");
});

Originally created by @rajkumar-cp on GitHub (Apr 4, 2025). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/4957 ### Is there an existing issue for this? - [x] I have searched existing issues and this bug hasn't been reported yet ### Current behavior A test script that works successfully when executed from the Hoppscotch web UI fails with a SyntaxError when run from the CLI. The error message indicates that "[object Object]" is not valid JSON. ### Steps to reproduce 1. Execute a test which gives response with an array. 2. Verify that all tests pass successfully, and the expected values are returned. 3. Execute the same test script using the Hoppscotch CLI. 4. Observe the failure and error message. ### Logs and Screenshots ```shell <system-err><![CDATA[ TEST_SCRIPT_ERROR - Script execution failed: SyntaxError: "[object Object]" is not valid JSON]]></system-err> ``` ### Environment Production ### Hoppscotch Version Self-Hosted (v2025.2.3) ### Interceptor Extension - Web App ### Browsers Affected Chrome ### Operating System Windows ### Additional Information **Sample response which i am trying to validate** { "TransactionID": "eb8d75d0", "ResponseDate": "2025-04-04", "ResponseTime": "14:01:03", "Company": [ { "BusinessPartnerID": "e327c8d1-15bc", "Error": "" } ] } **Sample test which works fine in both web and CLI** // Checking if the status code of the request is 200 (successful) pw.test("Status code is 200", () => { pw.expect(pw.response.status).toBe(200); }); // Checking if the TransactionID is returned in the response pw.test("TransactionID should not be empty", () => { pw.expect(pw.response.body.TransactionID).not.toBe(""); }); **Sample test which works fine in web and fails in CLI** // Storing the response from the api call as Response, the company's BusinessPartnerID stored as CBPID const Response = JSON.parse(pw.response.body); const CBPID = Response.Company[0].BusinessPartnerID; //Setting the environment variable CBPID with the value received in the response pw.env.set("CBPID", CBPID); //Checking if the status code of the request is 200 (successful) pw.test("Status code is 200", ()=> { pw.expect(pw.response.status).toBe(200); }); //Checking if the TransactionID is returned in the response pw.test("TransactionID should not be empty", () => { pw.expect(Response.TransactionID).not.toBe(""); }); //Checking if the error field in the response is empty pw.test("Error should be empty", () => { pw.expect(Response.Company[0].Error).toBe(""); });
Author
Owner

@muellerst-hg commented on GitHub (Apr 9, 2025):

I could reproduce with the following scenario:

Given I send a request to a test API
When the HTTP response header is:
  content-type: "application/octet-stream"
And the HTTP response body is:
  {"test": "123"}
Then pw.response.body is of type object in hopp cli
But pw.response.body is of type string in hoppscotch web ui

Therefore the following line in your Tests fail in cli but succeed in web ui:

const Response = JSON.parse(pw.response.body);

IMO both web ui and cli should behave like the same.

<!-- gh-comment-id:2789425279 --> @muellerst-hg commented on GitHub (Apr 9, 2025): I could reproduce with the following scenario: ``` gherkin Given I send a request to a test API When the HTTP response header is: content-type: "application/octet-stream" And the HTTP response body is: {"test": "123"} Then pw.response.body is of type object in hopp cli But pw.response.body is of type string in hoppscotch web ui ``` Therefore the following line in your Tests fail in cli but succeed in web ui: ```js const Response = JSON.parse(pw.response.body); ``` IMO both web ui and cli should behave like the same.
Author
Owner

@muellerst-hg commented on GitHub (Apr 9, 2025):

A workaround could be:

if (typeof(pw.response.body) === 'string') {
  var Response = JSON.parse(pw.response.body);
} else {
  var Response = pw.response.body;
}

or try changing content-type to "application/json" in the http reponse header.

<!-- gh-comment-id:2789432814 --> @muellerst-hg commented on GitHub (Apr 9, 2025): A workaround could be: ```js if (typeof(pw.response.body) === 'string') { var Response = JSON.parse(pw.response.body); } else { var Response = pw.response.body; } ``` or try changing content-type to "application/json" in the http reponse header.
Author
Owner

@rajkumar-cp commented on GitHub (Apr 9, 2025):

Thanks @muellerst-hg this helped me.

Changing the bug title to make more sense.

<!-- gh-comment-id:2789673909 --> @rajkumar-cp commented on GitHub (Apr 9, 2025): Thanks @muellerst-hg this helped me. Changing the bug title to make more sense.
Author
Owner

@Red44 commented on GitHub (Sep 12, 2025):

I have the same issues for the webui, where octet-streams content is sent as just "[object Object]" and also there seems to be an error, when requesting the shell curl command for that request. I can also confirm that the "[object Object]" response is a regression from at least version 2024.9.3

<!-- gh-comment-id:3285027230 --> @Red44 commented on GitHub (Sep 12, 2025): I have the same issues for the webui, where octet-streams content is sent as just "[object Object]" and also there seems to be an error, when requesting the shell curl command for that request. I can also confirm that the "[object Object]" response is a regression from at least version 2024.9.3
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/hoppscotch#1874
No description provided.