1
   Scenario: jsonPath demo
        * def jsonRequest =
    """
    {
    "name": "Test",
    "description": "Test Desc",
    "data": [
    {
    "language": "French",
    "messageText": "Warning",
    "helpText": "helpText 1"
    },
    {
    "language": "German",
    "messageText": "Warning2",
    "helpText": "helpText 2"
    },
    {
    "language": "English",
    "messageText": "Warning3",
    "helpText": "helpText 3"
    }
    ]
    }
    """


And print " jsonRequest.translationList[*].messageText ", karate.jsonPath(jsonRequest, "$.data[*].language") // it works and output is ["French","German","English"]

And print " jsonRequest.translationList[*].messageText ", jsonRequest.data[*].language // this does not work.

I am looking for the output ["French","German","English"] without using karate.jsonPath(), do we have any shortcut approach to get the same output when using karate.jsonPath().

Shreyansh Jain
  • 498
  • 4
  • 7
  • please refer this and you should get a solution, feel free to post an answer yourself: https://stackoverflow.com/a/76091034/143475 – Peter Thomas Jun 13 '23 at 09:22
  • @Peter Thomas, I checked this link and it sounds like functions find(), map() and filter() can be applied on the response object. I tried using find() on jsonRequest variable declared at the top in the question but I am getting below error. org.graalvm.polyglot.PolyglotException: {name=Test, description=Test Desc, data=[{"language":"en","messageText":"Warning","helpText":"helpText 1"},{"language":"en-gb","messageText":"Warning_UK","helpText":"helpText 2"},{"language":"en-us","messageText":"Warning_US","helpText":"helpText 3"}]} failed due to: Unknown identifier: find – Shreyansh Jain Jun 13 '23 at 09:40
  • 1
    Finally, I found a way to get the languages. * def allLanguages = $jsonRequest.data[?(@.language!= null)].language * print allLanguages – Shreyansh Jain Jun 13 '23 at 19:09

0 Answers0