1

JSON structure:

{ "id": "occvv",
"choice": [
{
"id": "e3A",
"Name": "Discover",
"Type": "NT_BE",
"Count": 4,
"items": [
{
"item": {
Wishlite: True
Test:false
},
"wishlisted": true
},
"item": {
Wishlite: True
Test:false
},
"wishlisted": true
},
"item": {
Wishlite: True
Test:false
},
"wishlisted": true
},
"item": {
Wishlite: True
Test:false
},
"wishlisted": true
},
],
"created": "2022-08-01T17:07:34.053238Z"
},
{
"id": "e455",
"Name": "new2",
"Type": "test44",
"Count": 3,
"items": [
{
"item": {
Wishlite: True
Test:false
},
"wishlisted": true
},
"item": {
Wishlite: True
Test:false
},
"wishlisted": true
},
"item": {
Wishlite: True
Test:false
},
"wishlisted": true
},
],
"created": "2022-08-01T17:07:34.053238Z"
},

Karate Code

Given url baseUrl
And path  PathUrl
And request { body }
When method Post
Then status <responseCode>
Then print response
* def responseobj = response
* def listtype = karate.jsonPath(response,"$..choice..Type")
* print 'listtype',listtype
* def fun = function(arg) { return karate.jsonPath(arg,'$..choices..items.item') }
* karate.forEach(listtype, fun)

I am trying to print all the item count under items for all the listtype by using for each.

For Karate.forEach passing listtype and Fun as parameters

1 Answers1

0

Just do this: https://github.com/karatelabs/karate#karate-sizeof

* def size = karate.sizeOf(listtype)
* print size
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Thanks @peter , I am trying to print the size of items for each List type. for example list type 1 has 10 items, under it and list type 2 has 7 items below it – Muthukannan doodleblue QA Engi Aug 02 '22 at 05:40
  • @MuthukannandoodleblueQAEngi I gave you a way to get the length of any list or map. your question is how to filter data. can you please read this: https://stackoverflow.com/a/72744312/143475 and this: https://stackoverflow.com/a/72691069/143475 – Peter Thomas Aug 02 '22 at 05:42