1

I am getting error while retrieving values A,B, C using jsonpath

Error:

karate.jsonPath(response, "$.code[*~]"), com.jayway.jsonpath.InvalidPathException: Expected wildcard token to end with ']'
  • def value = karate.jsonPath(response, "$.code[*~]")
  • def value_expected = ["A","B","C"]
  • match value contains only value_expected

Response is as below:

 {
      "code": {
        "A": [
          {
            "codeValue": 510575,
            "Key": "XYZ"
          }
        ],
        "B": [
          {
            "codeValue": 510575,
            "Key": "XYZ"
          }
        ],
        "C": [
          {
            "codeValue": 510575,
            "Key": "XYZ"
          }
        ]
      }
    }

1 Answer 1

1

I don't recommend JsonPath for cases like this, e.g. getting keys, it is really hard. Please use the Karate JSON transforms: github

* def keys = []
* def fun = function(k, v){ karate.appendTo(keys, k) }
* karate.forEach(response.code, fun)
* match keys == ['A', 'B', 'C']
Sign up to request clarification or add additional context in comments.

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.