mardi 23 juin 2020

Karate loop returns Json array as objects {}

I'm using Karate loops to generate dynamic Json. One of my test data contains array within an object. When I use karate loop on this data, the array is returned as an object.

* def fun = function(i){ return { "name": "userName"+ i, "email": "Tester@test.com", "id": "ID"+i, "testSheet": [{"sheetId" : "123"}]} }
* def jsonBody = karate.repeat(3, fun)
* print jsonBody

I'm expecting below:

[
  {
    "name": "userName0",
    "email": "Tester@test.com",
    "id": "ID1",
   "testSheet": [
        {
          "sheetId": "123"
        }
      ]
  }
]

But it returns this

[
  {
    "name": "userName0",
    "email": "Tester@test.com",
    "id": "ID1",
   "testSheet": {
       "0": {
          "sheetId": "123"
        }
      }
  }
]

Expected path: jsonBody[0].testSheet[0].sheetId

Actual path: jsonBody[0].testSheet.0.sheetId

Aucun commentaire:

Enregistrer un commentaire