0

I want to read objects from the main array filtering by refPath using JsonPath Jayway Java implementation.

My input looks like this:

[
   {
      "2be3d660-cab0-4db8-83b9-1baf212270c5" : {
         "refPath" : [
            "e0586818-ba2c-4b65-afec-3c48d817b584",
            "06c089a6-4de0-43d3-8dc7-181addf4c933",
            "d5413a18-ac33-426c-982d-bb25ce4e4bf6"
         ],
         "elementId" : "12c5750e-9753-43f1-8987-9dfc3a830bbe",
         "modified" : false
      },
      "191b1bab-c269-495f-ac4f-8b4d30df95a1" : {
         "refPath" : [
            "e0586818-ba2c-4b65-afec-3c48d817b584",
            "f7df7cff-bf6d-49da-bc44-90d61f233d3b"
         ],
         "elementId" : "04691514-566b-47ef-8f69-e31884bde7b2",
         "modified" : false
      },
      "6a2acd79-135f-4688-9219-158f91d9c6cf" : {
         "refPath" : [
            "e0586818-ba2c-4b65-afec-3c48d817b584",
            "f5177f79-e2f1-4419-b46a-7d4cc1c4fae5"
         ],
         "elementId" : "04691514-566b-47ef-8f69-e31884bde7b2",
         "modified" : false
      }
   }
]

and I want to find all objects containing these two refPath values: "e0586818-ba2c-4b65-afec-3c48d817b584" and "06c089a6-4de0-43d3-8dc7-181addf4c933"

So my expected result from JsonPath looks like:

[
       {
          "2be3d660-cab0-4db8-83b9-1baf212270c5" : {
             "refPath" : [
                "e0586818-ba2c-4b65-afec-3c48d817b584",
                "06c089a6-4de0-43d3-8dc7-181addf4c933",
                "d5413a18-ac33-426c-982d-bb25ce4e4bf6"
             ],
             "elementId" : "12c5750e-9753-43f1-8987-9dfc3a830bbe",
             "modified" : false
          }
       }
]

enter image description here

Even with if I only try to find "e0586818-ba2c-4b65-afec-3c48d817b584", I get an error message "Could not determine value type".

Does anybody have an idea how the JsonPath expression must look like for this?

0

1 Answer 1

0

Use the subsetof filter operator.

$[*][*][?(['e0586818-ba2c-4b65-afec-3c48d817b584','06c089a6-4de0-43d3-8dc7-181addf4c933'] subsetof @.refPath)]

Output will not include the key 2be3d660-cab0-4db8-83b9-1baf212270c5

[
   {
      "refPath" : [
         "e0586818-ba2c-4b65-afec-3c48d817b584",
         "06c089a6-4de0-43d3-8dc7-181addf4c933",
         "d5413a18-ac33-426c-982d-bb25ce4e4bf6"
      ],
      "elementId" : "12c5750e-9753-43f1-8987-9dfc3a830bbe",
      "modified" : false
   }
]
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.