0

I have tried to create GPath expression with filter criteria to return "my-notes" in list of object when '"my-type"' is SPECIAL

like : '"data.my-node.nodes.findAll{it.'my-type'=='GENERAL'}.'my-nodes'"'

but unable to get response from the below json

{
   "data": {"my-node":    [
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "abcdefg"}],
            "my-type": "GENERAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "abcdefg"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "oiugitoirtuhou"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "ifuoirjhihj"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "idfgdiufgdhsfuihdf"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "iydfgsigdfgdgidsf"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      }
   ]}
}
saba
  • 539
  • 1
  • 14
  • 30

1 Answers1

0

The GPath syntax is

List<?> value = JsonPath.from(res).get("data['my-node'].nodes.flatten().findAll{it.'my-type'=='GENERAL'}['my-nodes'].flatten()");
System.out.println(value);
//[{my-note=abcdefg}]
  • First, use ['key-abc'] for keys contain special characters.
  • Second, use flatten() method to make 2D array to 1D array.
lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20