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