Getting JSONError: Unexpected token '{' when i run pm.response.json() in test script for chuncked Json data

Hi folks,

When i parse the json body by pm.response.json() I am getting ( JSONError: Unexpected token ‘{’ ) This error , My response will be in chunked- JSON format.

Kindly Help me how can i parse the response and check for a value in the response via test scripts.

Response sample :- {
“groups”: [
{
“name”: “My Company”,
“objId”: “ttt-tt-tt-tt-tt”
},
{
“name”: “Test123 my company test”,
“objId”: “ttt-yy-yy-yy-tttt”
}]
}

{
“groups”: [
{
“name”: “My Company”,
“objId”: “ttt-tt-tt-tt-tt”
},
{
“name”: “Test123 my company test”,
“objId”: “ttt-yy-yy-yy-tttt”
}]
}

Hey @siba19, Welcome to the community :tada:

I think the issue is with and which is making your response as string (which is fine) but when I am trying to convert the string into JSON it gets broken with below error.

Screenshot 2022-03-03 at 1.53.17 PM

Please try changing your response with below one:

{
    "groups": [
        {
            "name": "My Company",
            "objId": "ttt-tt-tt-tt-tt"
        },
        {
            "name": "Test123 my company test",
            "objId": "ttt-yy-yy-yy-tttt"
        }
    ]
}

Cheers