-1

I would like to return the whole JSON if a condition is matched.

Test Json:

    {
            "EVENTID": 2624367601,
            "RECEIVERNAME": "CM.MYHR",
            "SENDERNAME": "CM.EIS.CF1",
            "AGREEMENTNAME": null   
    }

I keep trying in https://jsonpath.curiousconcept.com, but couldn't figure it out. I thought the following expression should work, but it always return empty.

$.[?(@.SENDERNAME==CM.EIS.CF1)]

Please help.

Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45
Autorun
  • 319
  • 2
  • 8
  • 20

2 Answers2

0

You only have a fragment of a json. Try it like this:

{
  "events": [
{
            "EVENTID": 2624367601,
            "RECEIVERNAME": "CM.MYHR",
            "SENDERNAME": "CM.EIS.CF1",
            "AGREEMENTNAME": null   
    }

]
}

And use:

$.*[?(@.SENDERNAME=='CM.EIS.CF1')]
Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45
  • Thanks Jack. Since I can't change my input JSON format which is not an array, does it mean I can't use jsonPath filtering which works on ARRAY only? Any alternatives or workaround on filtering a plain json? – Autorun Mar 02 '20 at 18:28
  • @Autorun - You can do that (or something like that) using python and a couple of json and jsonpath libraries; they can process your original test json without needing to modify it. I can give you more info (or post an answer) if that's relevant to you. – Jack Fleeting Mar 02 '20 at 20:26
0

If you want while json as it is from input, then as per my understanding you have to use below expression:

$.

I have tested it in https://jsonpath.curiousconcept.com/

Sumit2500
  • 183
  • 7