JSONError | No data, empty input at 1:1

16,299

You could use this to do the same thing:

if (pm.response.code === 204) { 
    pm.test(`Engine is suspended with resposne code ${pm.response.code}`, () => { 
        console.log(pm.response.code); 
    }) 
}
else { 
    pm.test(`Staging is resumed with message ${pm.response.json().stagresbody.serviceStatus}`, () => {
        console.log(`Staging is resumed with message ${pm.response.json().stagresbody.serviceStatus}`);
    }); 
}
Share:
16,299
Shiva. N
Author by

Shiva. N

Updated on June 04, 2022

Comments

  • Shiva. N
    Shiva. N almost 2 years

    I'm tring to print the response code in the console, but i always end up in getting the response as "JSONError | No data, empty input at 1:1"

    im getting this error when the response code is 204. else condition works fine.

    script is not entering to the condition.

    please review the code and provide a solution. Thanks.

    var respcode=pm.response.code;
    var stagresbody=pm.response.json(responseBody);
    
    if (respcode === 204) { 
        pm.test("engine is suspended with resposne code"+respcode,function(){ 
            console.log(respcode); 
        }) 
    }
    else { pm.test("Staging is resumed with message"+stagresbody.serviceStatus,function(){
        console.log("Staging is resumed with message "+stagresbody.serviceStatus);
        }); 
    }
    
    • Shiva. N
      Shiva. N over 4 years
      var respcode=pm.response.code; var stagresbody=pm.response.json(responseBody); if (respcode === 204) { pm.test("engine is suspended with resposne code"+respcode,function(){ console.log(respcode); }) } else { pm.test("Staging is resumed with message"+stagresbody.serviceStatus,function(){ console.log("Staging is resumed with message "+stagresbody.serviceStatus); }); }
    • Danny Dainton
      Danny Dainton over 4 years
      You should just need to use pm.response.json() without adding responseBody
    • Danny Dainton
      Danny Dainton over 4 years
      It would be better if you added your comment to the original question and format the code.
    • inputforcolor
      inputforcolor over 4 years
      Welcome to Stack Overflow _ I have taken the code you wrote in your comment and put it in a code block within the question. Please review the code block to ensure that nothing has been left out from the commented code
    • Shiva. N
      Shiva. N over 4 years
      @inputforcolor thx for that.. from next time on ill add it in question.
    • Shiva. N
      Shiva. N over 4 years
      @DannyDainton; if i do not use responseBody, the console log is not showing any output just shows as object . Not sure why the code is not working if the response code is 204. And when get response code as 204 the response body do not have anything. so i'm using response code to print on out put
    • Danny Dainton
      Danny Dainton over 4 years
      pm.response.json() is the correct syntax pm.response.json(responseBody) is something you've made up 😁 - it will work that wrong way as that function ignores any arguments inside it.
    • Danny Dainton
      Danny Dainton over 4 years
      It's more than likely failing on the 204 because for both conditions, you're still parsing the response body - If the 204 response returns no body, it's still trying to parse...well, nothing and then throws the error.
  • Danny Dainton
    Danny Dainton over 4 years
    Don't forget to upvote or accept the answer if it helped you. 😁