# 15 days of Postman for tester - Day 07: Wrong Json format in the response body of https://postman-echo.com/post

**URL:** <https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066>\
**Category:** Help Hub\
**Created:** [May 4, 2023, 8:08am UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066 "2023-05-04T08:08:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![annq00](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@annq00](https://community.postman.com/u/annq00)\
**Post date:** [May 4, 2023, 8:08am UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066/1 "2023-05-04T08:08:09Z")

</div>

I stumbled on a problem after submitting the collection for day 7  
Below was what I did  
After I submitted my collection, the 8th assertion was failed  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/5/8/583e6d4fe13abd2ad94f826ba2c9505256fdf061.png)  
And in the test script below, the echoRequest.event was undefined

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/4/a/4a18bb37cd2e8f93c75b0805decee86c6ad6af73.png)  
My “echo the user” API  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/5/c/5c21c3712c72625afd94deb3108d41e6ddd65cc3.png)  
as you can see in the console, the value of the “data” field is not JSON but a String!  
However, the 8th assertion in the submit collection API is checking for this particular string “pm.response.json” in the test script of the “echo the user” API, otherwise, I could just use the pm.repsonse.text() method instead.  
After doing some research on the internet and ask the chat GPT, I’m not entirely sure if the failure of the 8th assertion is the wrong formatted json body or not. So, please feel free to share your insights :v

P/s: I think this issue has just occurred recently. I vividly remembered the response body of the echo API was neat and tidy when I did the day 5 challenge

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [May 4, 2023, 10:18am UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066/2 "2023-05-04T10:18:38Z")

</div>

This is using Postman echo, and it should be returning an object, not a string.

What does your body look like as Postman echo just echo’s the body back under the data element.

I get this from time to time when using Postman Echo, where the body looks fine but it keeps returning a string.

Sometimes I have to paste the body into notepad to remove any potential extra formatting, and then paste it back in which can fix the issue. Make sure all of the quotes are normal double quotes, etc as that can also affect it.

For this particular challenge, the variables in the body need to be within quotes like following.

```auto
  "name": "{{name}}",

```

---

<div class="post-metadata">

**Author:** ![annq00](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@annq00](https://community.postman.com/u/annq00)\
**Post date:** [May 4, 2023, 10:27am UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066/3 "2023-05-04T10:27:22Z")

</div>

Thanks for your response, but I don’t think it is the case. Below is my echo request’s body

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/e/3/e3a6d82a3be81667ae2516d40c93ceeda653d9dd.png)  
I don’t have any problems with the challenge, the problem is lying within the test script of the submit collection API. For some reasons, the “event” variable of the below block of code is undefined. I wonder if the reason is due to the incorrect formatted of the echo API’s response body

> pm.test(“Echo test added”, () =\> {  
> let echoRequest = folder.item.find(req =\> { return req.name === “echo the user”})  
> console.log(echoRequest)  
> console.log(echoRequest.event)  
> let event = echoRequest.event.find(e =\> {return e.listen === “test”})  
> pm.expect(event.script.exec.toString(), ‘check parse object’).contains(“pm.response.json”)  
> pass += 1  
> })

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [May 4, 2023, 10:32am UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066/4 "2023-05-04T10:32:26Z")

</div>

Put the variables in the body in quotes, and then see if it returns an object.

```auto
{
  "name": "{{name}}",
  "email": "{{email}}",
  "uuid": "{{uuid}}"
}

```

---

<div class="post-metadata">

**Author:** ![phthanhxuan](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@phthanhxuan](https://community.postman.com/u/phthanhxuan)\
**Post date:** [May 4, 2023, 11:07am UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066/5 "2023-05-04T11:07:33Z")

</div>

Could you please share the test script of the “echo the user” folder?  
I got stuck because my test case “Collection variables set” failed.

My scripts are as below:  
**1. GET Canadian user**  
Param key: nat - value: CA  
Tests:  
//set collection variables

let responseJsonData = pm.response.json();  
console.log(responseJsonData);  
pm.collectionVariables.set(“userdata”, responseJsonData);

**2. POST echo the user**  
\*Pre-request scripts:

let userdata = pm.collectionVariables.get(“userdata”).results[0];  
//set name variable

let fname = userdata.name.first;  
let lname = userdata.name.last;  
let fullname = Object.values([fname,lname]).join(" ");

pm.collectionVariables.set(“name”, fullname);

//set email variable

let email = userdata.email;  
pm.collectionVariables.set(“email”, email);

//set uuid variable

let uuid = userdata.login.uuid  
pm.collectionVariables.set(“uuid”, uuid);

Body:  
{  
“name”: “{{name}}”,  
“email”: “{{email}}”,  
“uuid”: “{{uuid}}”  
};

Test submit collection failure:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/f/9f2f58ce822989bf569859a0697ef12cd31ff75e.png)

Hope to hear from you \<3

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [May 4, 2023, 11:20am UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066/6 "2023-05-04T11:20:04Z")

</div>

@phthanhxuan

First of all, this should be its own question. Rather than hi-jacking someone else’s question (which is not related apart from its the same challenge).

I can only recommend to re-read the instructions. These challenges aren’t meant to catch you out, and telling you the answers defeats the main purpose of the challenges\training.

Take a step back and think about the error message.

It’s expecting a variable in the GET request called ‘name’.

You are meant to set the collection variables for name, email and UUID from the GET request response as individual elements in the tests tab.

You’ve set an collection variable called ‘userdata’ using the full response which you then pull apart in the pre-request script for the POST request. You don’t need to do this in the pre-request script. Just set the collection variables for the three elements from the GET request.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [May 4, 2023, 12:04pm UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066/7 "2023-05-04T12:04:40Z")

</div>

@annq00

I’m not sure that the formatting of the body would break the test. But is something that should be corrected as it should be returning an object.

![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/a/3aeced2dcd7aea2e0ecee9838f36f4071ca8af11.png)

Have a look at the response when you submit the collection.

Try and find the item object for “echo the user”.

The beginning of it should look something like the following. The event is related to the tests tab, not the body.

```auto
{
    "name": "echo the user",
    "event": [
        {
            "listen": "test",
            "script": {
                "id": "64ef265a-8115-4690-a957-e40af4f6ee6a",
                "exec": [
                    "const response = pm.response.json().data\r",
                    "\r",
                    "\r",
                    "pm.test(`Returns correct email: ${pm.collectionVariables.get('email')}`, function () {\r",
                    " pm.expect(response.email).to.eql(pm.collectionVariables.get('email'));\r",
                    "})"
                ],
                "type": "text/javascript"
            }
        }
    ],

```

It should also match up with your console logs.

```auto
console.log(echoRequest)

```

It does on face value look like the event element is not appearing in the collection. You should be able to console log it as you have done.

---

<div class="post-metadata">

**Author:** ![phthanhxuan](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@phthanhxuan](https://community.postman.com/u/phthanhxuan)\
**Post date:** [May 4, 2023, 12:08pm UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066/8 "2023-05-04T12:08:28Z")

</div>

@michaelderekjones

Dear Mr. Mike,

I apologize for my irrelevant question on this topic.

I misunderstood the instructions. I have followed your instruction and successfully redone it correctly.

Thank you so much for your reply!!

---

<div class="post-metadata">

**Author:** ![annq00](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@annq00](https://community.postman.com/u/annq00)\
**Post date:** [May 4, 2023, 2:06pm UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066/9 "2023-05-04T14:06:52Z")

</div>

Dude, after I tried to submit my collection again, for some unknown reasons all of 8 assertions passed !!?  
I have not changed anything at all since I posted this topic.  
About the response of my “echo the user” API, it’s still the same. The value of “data” is a string with \r\n all over the place

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/a/ba926454d5e13596565a1be5e67d066f9bbf4ebc.png)

Now when I check the echoRequest and echoRequest.event with console.log, the result of echoRequest.event is no longer undefined which is of course because the test no longer fails

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/3/3358f4782960668e31b339a0245f61c9f19e8757.png)

I literally have not changed anything at all and suddenly it works. Still confused as hell.  
Anyway, thanks a lot for trying to help me out. Have a nice day.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [May 4, 2023, 2:49pm UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066/10 "2023-05-04T14:49:09Z")

</div>

Fair enough. Glad its passing now.

in relation to data showing a string instead of an object, you still haven’t updated the body to wrap the variables in quotes.

```auto
{
  "name": "{{randomUserName}}",
  "email": "{{randomEmail}}",
  "uuid": "{{randomUuid}}"
}

```

---

<div class="post-metadata">

**Author:** ![annq00](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@annq00](https://community.postman.com/u/annq00)\
**Post date:** [May 4, 2023, 4:02pm UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066/12 "2023-05-04T16:02:22Z")

</div>

wow, it takes me a while to realize what you have been trying to tell me to do.  
I did missed those quotes in my body. It worked well in the day 5 challenge without the quotes so I did not think twice about it. Btw I actually thought that you were referring to the double curly brackets since quote could be translated to that in my mother tongue. Silly me :v  
Now it’s all clear. Thanks a ton, man xD

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [March 19, 2024, 10:28am UTC](https://community.postman.com/t/15-days-of-postman-for-tester-day-07-wrong-json-format-in-the-response-body-of-https-postman-echo-com-post/47066/13 "2024-03-19T10:28:53Z")

</div>

Closed on March 19, 2024, 10:28am UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
