0

I want to get the count of faultInfoLst element from the below json array. I want to do an operation based on the count of that element. Help me to get count as I have to set it in session variable in mule flow.

[{"TaskInfo":
    {"faultInfo":
        {
            "errCode":"",
            "errDesc":"",
            "errSystem":""
        }
    }
},
{"TaskInfo":
    {"faultInfo":
        {
            "errCode":"",
            "errDesc":"",
            "errSystem":"",
            "errStack":""
        }
    }
}]
Matthew
  • 1,630
  • 1
  • 14
  • 19
lucky
  • 75
  • 1
  • 9

1 Answers1

1

It seems that your goal can be achieved by simply getting the size of the array. It seems there's indeed a 1:1 relationship with faultInfo and TaskInfo.

So based on: http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+Tips#MuleExpressionLanguageTips-JSONProcessing

<json:json-to-object-transformer returnClass="java.lang.Object" />
<set-variable variableName="faultInfoCount"
    value="#[($ in message.payload if $.TaskInfo.containsKey('faultInfo')).size()]" />
David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • no david,fault info comes in taskinfo only if fault exists in the response.so it may come or may not come.i.e sometimes fault comes in taskinfo and some times it doesnt come. – lucky May 12 '14 at 07:08
  • OK this wasn't clear from your example. I'll refactor my answer. – David Dossot May 12 '14 at 14:16
  • Done, this new version filters the `TaskInfo` elements based on the existence of `faultInfo`. – David Dossot May 12 '14 at 19:30