# I want to do message field validation but i am getting

**URL:** <https://community.postman.com/t/i-want-to-do-message-field-validation-but-i-am-getting/42797>\
**Category:** Help Hub\
**Tags:** tests, json\
**Created:** [January 11, 2023, 4:46pm UTC](https://community.postman.com/t/i-want-to-do-message-field-validation-but-i-am-getting/42797 "2023-01-11T16:46:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kallol-sarker](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@kallol-sarker](https://community.postman.com/u/kallol-sarker)\
**Post date:** [January 11, 2023, 4:46pm UTC](https://community.postman.com/t/i-want-to-do-message-field-validation-but-i-am-getting/42797/1 "2023-01-11T16:46:00Z")

</div>

![1](https://us1.discourse-cdn.com/getpostman/original/3X/c/b/cb2e02355218df4d68b0205802acdda24a3e189a.png)  
 ![2](https://us1.discourse-cdn.com/getpostman/original/3X/1/6/1613c25717ce37a6cc6494bdf521a661afa4a637.png)

Here are my JSON body and tests. how do i validate the message field that is “Add data success”  
Please help anyone knows.

---

<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:** [January 11, 2023, 5:14pm UTC](https://community.postman.com/t/i-want-to-do-message-field-validation-but-i-am-getting/42797/2 "2023-01-11T17:14:52Z")

</div>

The message is a bit misleading, as it appears to be reading the expected and actual result correctly.

I think its because the assertion is worded slightly incorrectly.

Shouldn’t it be…

```auto
pm.expect(jsonData.msg).to.equal("Add data success"); // not is.to.equal

```

---

<div class="post-metadata">

**Author:** ![kallol-sarker](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@kallol-sarker](https://community.postman.com/u/kallol-sarker)\
**Post date:** [January 14, 2023, 9:56am UTC](https://community.postman.com/t/i-want-to-do-message-field-validation-but-i-am-getting/42797/3 "2023-01-14T09:56:34Z")

</div>

![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/7/07d596ba9c0f891ee61c9561ee5a573eacd0f779.png)

Thank you for your reply. It’s not working. Now what should i do? Please let me know?

---

<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:** [January 14, 2023, 5:16pm UTC](https://community.postman.com/t/i-want-to-do-message-field-validation-but-i-am-getting/42797/4 "2023-01-14T17:16:27Z")

</div>

That is different than before.

Before your code was executing, but you weren’t getting the correct result.

The error you are now receiving seems to indicate that it can’t execute the tests. (Perhaps because your pm.expect is not wrapped in a test.

Could you please share all of the code in your Tests tab? Just in case something else is interfering with the test.

---

<div class="post-metadata">

**Author:** ![kallol-sarker](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@kallol-sarker](https://community.postman.com/u/kallol-sarker)\
**Post date:** [January 22, 2023, 4:12pm UTC](https://community.postman.com/t/i-want-to-do-message-field-validation-but-i-am-getting/42797/5 "2023-01-22T16:12:17Z")

</div>

Hey, here is my Json Code…

{  
“Permanent\_Address”:  
{  
“House\_Number”: “40/4”,  
“City”: “Dhaka”,  
“State”: “Dhaka”,  
“Country”: “Bangladesh”,  
“PhoneNumber”: [  
{  
“Std\_Code”: “1162090”,  
“Home”: “Tower Twenty Four”,  
“Mobile”: “+8801746684953”  
},  
{  
“Std\_Code”: “1110338426”,  
“Home”: “Tower twenty four”,  
“Mobile”: “+8801913903626”  
}  
]  
},  
“stId”: 4177479  
}

And here is my test code -

pm.test(“Status field value validation”, function () {  
pm.expect(jsonData.status).to.eql(“true”);  
});

pm.test(“Message field value validation”, function () {  
pm.expect(jsonData.msg).to.eql(“Add data success”);  
});

please look where is my mistake. And provide me some suggestion. Thanks.

---

<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:** [January 22, 2023, 7:59pm UTC](https://community.postman.com/t/i-want-to-do-message-field-validation-but-i-am-getting/42797/6 "2023-01-22T19:59:18Z")

</div>

That can’t be all of the test code, as I can’t see where you are parsing the response to the variable jsonData. Can you please include all of the code (and please use the preformatted text option in the editor so all of the code doesn’t get aligned to the left).

The following code seems to work fine.

```auto
jsonData = pm.response.json();

pm.test("Status field value validation", function () {
    pm.expect(jsonData.status).to.eql("true");
});

pm.test("Message field value validation", function () {
    pm.expect(jsonData.msg).to.eql("Add data success");
});

```

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

For troubleshooting purposes, duplicate the request, and paste the above into the Tests tab and remove anything else. Does it work then?

---

<div class="post-metadata">

**Author:** ![kallol-sarker](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@kallol-sarker](https://community.postman.com/u/kallol-sarker)\
**Post date:** [January 23, 2023, 12:16pm UTC](https://community.postman.com/t/i-want-to-do-message-field-validation-but-i-am-getting/42797/7 "2023-01-23T12:16:15Z")

</div>

1. Write a test case for Status Code Validation. Create Student Address  
METHOD: POST  
STATUS CODE: 200  
Base\_Url: [https://thetestingworldapi.com](https://thetestingworldapi.com)  
Request URL: baseUrl/api/addresses  
Body  
{ “Permanent\_Address”: { “House\_Number”: “sample string 1”,“City”: “sample string 2”, “State”: “sample string 3”, “Country”: “sample string 4”,“PhoneNumber”: [  
{ “Std\_Code”: “sample string 1”,“Home”: “sample string 2”, “Mobile”: “sample  
string 3”  
},{ “Std\_Code”: “sample string 1”,“Home”: “sample string 2”, “Mobile”: “sample  
string 3”  
}  
]  
},  
“stId”: id  
}  
Response: {  
“status”: “true”,  
“msg”: “Add data success”  
}
2. Write a test case for Status Code Validation. 3. Write a test case for status and message

Hey, how are you?  
Actually, this was my task and I want to validate the message field from the response data. but I can’t verify. I don’t know what’s the problem on my code. I have searched on google but I can not reach a specific result. please help if you can. Thank you.

---

<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:** [January 23, 2023, 12:40pm UTC](https://community.postman.com/t/i-want-to-do-message-field-validation-but-i-am-getting/42797/8 "2023-01-23T12:40:08Z")

</div>

Have you tried using the code I provided in the previous comment.

Make sure you don’t anything else in the test tab.

It should work.

---

<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:** [January 23, 2023, 12:48pm UTC](https://community.postman.com/t/i-want-to-do-message-field-validation-but-i-am-getting/42797/9 "2023-01-23T12:48:57Z")

</div>

The reason the second test is failing is because of the response.

It’s “Add data success” and has two spaces between Add and data.

Even this editor keeps removing the second space thinking its wrong. So its hard to spot at a glance. It’s more obvious if you see the screenshot.

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

```auto
pm.test("Message field value validation", function () {
    pm.expect(jsonData.msg).to.eql("Add data success");
});

```

---

<div class="post-metadata">

**Author:** ![kallol-sarker](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@kallol-sarker](https://community.postman.com/u/kallol-sarker)\
**Post date:** [January 23, 2023, 3:51pm UTC](https://community.postman.com/t/i-want-to-do-message-field-validation-but-i-am-getting/42797/10 "2023-01-23T15:51:23Z")

</div>

Thank you very much. Now it’s work. Thanks a lot.  
Take love
