1

I am trying to read a list from a specific object key cars

Input is jsonString:

{
  "id": 600000,
  "name": "Ayman",
  "cars": [
    {
      "manufacturer": "Volvo",
      "economy" : 65,
      "price" : 100000
    }
}

Desired output is:

"cars": [
  {
    "manufacturer": "Volvo",
    "economy" : 65,
    "price" : 100000
  }

Here is my code:

objectKey=$.cars[*]
JsonPath.parse(jsonString).read(objectKey);

I want to throw an exception if my objectKey is not present. Does JsonPath provide a mechanism to throw exception when key is not present?

0

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.