2

I have this piece of JSON response

"A": {
"RandomName01": {
    "B": "BOS",
    "C": {
        "RandomName02": {
            "D": "32",
            "E": "ABC",
            "F": "DEF"
        }
    },
    "G": "GHI"
}

I need to extract value of D from it, having two RandomName tags on the way. I can't find anything in documentation related to handling unknown names. I tried using [], *, [0], .. etc but I failed.

For example:

  • def value = response.A..C..D
  • def value = response[0].C[0].D

etc...

Thanks,

2 Answers 2

3

Thanks for help. Your answer has made me try jsonPath in karate

This has made a trick:

* def value = karate.jsonPath(response, "$..D")

To try jsonPath I used: http://jsonpath.com/

For jsonPath expressions I used: https://goessner.net/articles/JsonPath/index.html#e2

Thanks :)

Sign up to request clarification or add additional context in comments.

Comments

2

This should work,

* def value = response..["D"]

you can deepscan any key using .. operator

karate uses jsonpath for JSON manipulation.

Please refer Json path operators for more useful information.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.