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?

Ayman Arif
  • 1,456
  • 3
  • 16
  • 40

0 Answers0