Shiva. N
Shiva. N

Reputation: 33

JSONError | No data, empty input at 1:1

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);
    }); 
}

Upvotes: 2

Views: 32712

Answers (2)

Vikas Piprade
Vikas Piprade

Reputation: 352

My Postman Test has console log for json response. But my request would not give any response ( i.e. response body is blank ) and thereby giving "No data, empty input at 1:1" error. I resolved this problem by commenting logging of response.

pm.test("Status code is 200", function () {
pm.response.to.have.status(204);

});

// Below line would give me error "JSONError | No data, empty input at 
//1:1" as my request won't output ant response i.e. response body is blank.
// Commenting this line resolve problem.

*//console.log( pm.response.json()[0].name);*

Upvotes: 0

Danny Dainton
Danny Dainton

Reputation: 25881

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}`);
    }); 
}

Upvotes: 3

Related Questions