-1

I'm using the JSON path to my elaborate. I need to find all final leaves nodes which contain a specific string. Suppose you have a json :

{  'nested' :{
              'leaf1' : 'MY_STRING_TO_FIND'
           },
   'leaf2' : 'MY_STRING_TO_FIND'
}

my purpose is to output leaf1 and leaf2

Sohail Ahmad
  • 7,309
  • 5
  • 27
  • 46
Peter Pan
  • 9
  • 2

1 Answers1

0

The json string in your question is invalid, but if I understand your question correctly and assuming the actual json string looks something like this:

{
    "nested": {
        "leaf1": "MY_STRING_TO_FIND",
         "leaf2": "some other string",
        "leaf3": "MY_STRING_TO_FIND"
    }
}

and assuming you can use jsonpath-plus, then the following expression:

*[?(@ === "MY_STRING_TO_FIND")]~

outputs:

[
    "leaf1",
    "leaf3"
]
Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45