I want to extract some values and store in array in JSON format.
I have my code in karate-config.js file as the API I am calling needs to be called only once and the results needs to be stored in array so it can be later utilized inside other features.
var result = karate.callSingle('classpath:examples/users.feature@country',config);
config.array = []
for (var i=0; i<result.response.length; i++){
config.array.push({ 'userId': result.response[i].id, 'country': result.response[i].country});
}
karate.log(config.array)
Results
[object Object],[object Object]
Expected Results
[
{
"userId" : 931,
"country" : "USA"
},
{
"userId" : 709,
"country" : "HK"
}
]