Ashwini
Ashwini

Reputation: 63

Postman JSON value check test fails

I have an API which has response as below:

"data": {
"catalog_list_items": [
  {
    "catalog_list_items": [
      {
        "catalog_list_items": [
          {
            "title": "L13",
            "content_id": "58a85146b0000ec",
            "sequence_no": 1,
            "language": "hindi",
            "genres": [
              "xxxx"
            ]

I would like to create a test in postman to verify that the language key has value as 'hindi'. I am writing below test in Postman which always fails. Cannot find the reason.

var jsonData = JSON.parse(responseBody); 
tests["Language is hindi"] = jsonData.data.catalog_list_items[3].language === "hindi";

However, when I use the similar structure to test sequence_no, it works fine

var jsonData = JSON.parse(responseBody);    
tests["Sequence No is 1"]= jsonData.data.catalog_list_items[3].sequence_no   === 1;

Can anyone shed a light for me?

Upvotes: 1

Views: 7914

Answers (1)

Dinesh Kumar
Dinesh Kumar

Reputation: 1742

I could see 3 level nested arrays in your response body. So I don't know how are you getting your value through this expression: jsonData.data.catalog_list_items[3].language

The correct expression to get the 'language' key from above response should be:

jsonData.data.catalog_list_items[0].catalog_list_items[0].catalog_list_items[0].language

Upvotes: 3

Related Questions