Forum Discussion

gsingam's avatar
gsingam
Occasional Contributor
3 years ago

How to match the json sibling using expression

"Criteria" : [
{
"selectionCriteriaType" : "DEFENSE_REASONS",
"selectionCriteriaValue" : "AdditionalInformation"
},
{
"selectionCriteriaType" : "AVS_RESULT",
"selectionCriteriaValue" : "A"
},
{
"selectionCriteriaType" : "REFUND_STATE",
"selectionCriteriaValue" : "false"
},
{
"selectionCriteriaType" : "BILLING_ADDRESS",
"selectionCriteriaValue" : "false"
}

 

]

 

Above Json can be very huge and order of the elements  always changes. What would be my regular expression to match 

{
"selectionCriteriaType" : "REFUND_STATE",
"selectionCriteriaValue" : "false"
},

  • gsingam,

    I would use the following expression:

     

    $.Criteria[?(@.selectionCriteriaType=="REFUND_STATE" && @.selectionCriteriaValue=="false")]

     

    Please note your boolean elements are represented as strings now ("false" instead of false). I would recommend to fix it.

     

    Best regards,

    Karel

     

  • KarelHusa's avatar
    KarelHusa
    Champion Level 1

    gsingam,

    I would use the following expression:

     

    $.Criteria[?(@.selectionCriteriaType=="REFUND_STATE" && @.selectionCriteriaValue=="false")]

     

    Please note your boolean elements are represented as strings now ("false" instead of false). I would recommend to fix it.

     

    Best regards,

    Karel

     

  • gsingam's avatar
    gsingam
    Occasional Contributor

    Thank you very much. You and your solution is awesome.