How to I store dynamic key values in Karate?

30 Views Asked by At

Below is the payload where we need to store the value inside ABC->XYZ. Here "123456" is the dynamic key. Where this "123456" value is stored from previous api.

{
    "123456": {
        "Message": {
              "messageId": "abcd
        },
        "ABC": {
            "XYZ": "REQ123456"
        }
    },
}

I have tried with below snippet where I am getting value as "123456" instead of "REQ123456"

* def list = []
* def fun = function(k, v){ karate.appendTo('list', { key: k, val: v } )}
* karate.forEach(response, fun)
* def keys = $list[?(@.val.ABC.XYZ)].key
* print keys
0

There are 0 best solutions below