# Validating a JSON respons for testing gives incorrect test passed result

**URL:** <https://community.postman.com/t/validating-a-json-respons-for-testing-gives-incorrect-test-passed-result/6337>\
**Category:** Help Hub\
**Created:** [July 5, 2019, 8:32am UTC](https://community.postman.com/t/validating-a-json-respons-for-testing-gives-incorrect-test-passed-result/6337 "2019-07-05T08:32:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![edouard.verbeke](https://avatars.discourse-cdn.com/v4/letter/e/dc4da7/32.png) [@edouard.verbeke](https://community.postman.com/u/edouard.verbeke)\
**Post date:** [July 5, 2019, 8:32am UTC](https://community.postman.com/t/validating-a-json-respons-for-testing-gives-incorrect-test-passed-result/6337/1 "2019-07-05T08:32:45Z")

</div>

Hi,

I’m writing a test in Postman to check if my Get call returns a specific value in the json results. But the test is always ok no matter what the results in the json are.

This is my test:

```
pm.test("Browsestatus is completed", function () {
    var jsonData = JSON.parse(responseBody);
    pm.expect(jsonData.Internal.BrowseStatus) === ('failed');
    
});
pm.test("File is on disk", function () {
    var jsonData = JSON.parse(responseBody);
    pm.expect(jsonData.Internal.ArchiveStatus) === ("on_disk");
});
pm.test("OriginalStatus is completed", function () {
    var jsonData = JSON.parse(responseBody);
    pm.expect(jsonData.Internal.OriginalStatus) === ("completed");
});

```

this is my returned json:

“OriginalStatus”: “completed”,  
“BrowseStatus”: “failed”,  
“ArchiveStatus”: “failed”,

Anybody that can help?

thanks

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [July 5, 2019, 9:06am UTC](https://community.postman.com/t/validating-a-json-respons-for-testing-gives-incorrect-test-passed-result/6337/2 "2019-07-05T09:06:38Z")

</div>

Hey @edouard.verbeke,

Welcome and thank you for posting your question ⭐

I can see a couple of areas in your tests that might be solved by taking a look through this doc on our learning site.

[https://learning.getpostman.com/docs/postman/scripts/test\_scripts/](https://learning.getpostman.com/docs/postman/scripts/test_scripts/)

Also, that looks like a reduced output from the response as it seems to be missing some of the properties that you’re referencing in the tests.

---

<div class="post-metadata">

**Author:** ![edouard.verbeke](https://avatars.discourse-cdn.com/v4/letter/e/dc4da7/32.png) [@edouard.verbeke](https://community.postman.com/u/edouard.verbeke)\
**Post date:** [July 5, 2019, 9:14am UTC](https://community.postman.com/t/validating-a-json-respons-for-testing-gives-incorrect-test-passed-result/6337/3 "2019-07-05T09:14:46Z")

</div>

correct, the output is reduced, this is the whole JSON:  
(I’m reading your linked documents atm)

```
},
"Internal": {
    "MediaObjectId": "fc83600180ae4577abe557ca917b7d18f1c78d79d9b34482bc20f977fa6f0987",
    "FragmentId": "fc83600180ae4577abe557ca917b7d18f1c78d79d9b34482bc20f977fa6f098795bb55b975a1435f8a95d28197d1b51c",
    "OriginalStatus": "completed",
    "BrowseStatus": "failed",
    "ArchiveStatus": "failed",
    "UploadedById": "ff100b7a-efd0-44e3-8816-0905572421da",
    "OrganisationId": "100",
    "IngestSpaceId": "48969bab-ca82-4bed-9ecf-29e82ff5054f",
    "IsInIngestSpace": true,
    "IsFragment": false,
    "HasKeyframes": false,
    "ContainsGeoData": false,
    "PathToKeyframe": "http://dev-storage-virtual.mediahaven.com/DEV/no-preview.png",
    "PathToKeyframeThumb": "http://dev-storage-virtual.mediahaven.com/DEV/no-preview.png",
    "DepartmentId": null,
    "Browses": {},
    "PathToVideo": null
},
"Context": {
    "IsEditable": true,
    "IsDeletable": true,
    "IsPublic": true,
    "IsExportable": true
}

```

}

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [July 5, 2019, 9:20am UTC](https://community.postman.com/t/validating-a-json-respons-for-testing-gives-incorrect-test-passed-result/6337/4 "2019-07-05T09:20:10Z")

</div>

Thank you.

To me, that also doesn’t look like the whole response or it’s just the way it’s been formatted. 🙂

It will make a big difference in your assertions (`pm.expect()`), if all the data is returned inside an _array_ `[...]` - Just something to think about when you’re writing tests.

---

<div class="post-metadata">

**Author:** ![postman-paul540](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/postman-paul540/32/149_2.png) [@postman-paul540](https://community.postman.com/u/postman-paul540)\
**Post date:** [July 5, 2019, 9:41am UTC](https://community.postman.com/t/validating-a-json-respons-for-testing-gives-incorrect-test-passed-result/6337/5 "2019-07-05T09:41:26Z")

</div>

I’m leaving this here incase any beginners stumbles across this post.  
Paste the below into the Tests tab in Postman:

```auto
// I've copied and paste the example JSON you sent me as a MOCK, so hitting the below URL will return the JSON your sent to me.
// This may need updating to match your response exactly, but basically you were writing your tests wrong ^_^
   
// Example MOCK URL:
//http://www.mocky.io/v2/5d1f1624310000016aebea7f

var jsonData = pm.response.json();
pm.test("Response time is less than 1500", function() {
    pm.expect(pm.response.responseTime).to.be.below(1500);
});

pm.test("Show File", function () {
    pm.response.to.have.status(200);
});

pm.test("Browsestatus is completed", function () {
    pm.expect(jsonData.Internal).to.have.property("BrowseStatus", "failed");
});

// This one is puposely failing to prove that Postman is reporting failures.
pm.test("File is on disk", function () {
    pm.expect(jsonData.Internal).to.have.property("ArchiveStatus", "on_disk");
});

pm.test("OriginalStatus is completed", function () {
    pm.expect(jsonData.Internal).to.have.property("OriginalStatus", "completed");
});

```

---

<div class="post-metadata">

**Author:** ![edouard.verbeke](https://avatars.discourse-cdn.com/v4/letter/e/dc4da7/32.png) [@edouard.verbeke](https://community.postman.com/u/edouard.verbeke)\
**Post date:** [July 5, 2019, 9:46am UTC](https://community.postman.com/t/validating-a-json-respons-for-testing-gives-incorrect-test-passed-result/6337/6 "2019-07-05T09:46:44Z")

</div>

Hi pfarrell,

Thank you so much! Works perfectly now! Have a nice day friendly person from the internet!!
