2

I want to perform some string operation on MEL I have following expression in MEL

<logger message="#[json:xy/PID/xy.3/AC]" level="INFO" doc:name="Logger"/>

OUTPUT IS

19901026000000

I want to extract 1st 4 digit then 6,7 digit .

How can I do this ??

Thanks

user3855589
  • 1,113
  • 2
  • 15
  • 43

3 Answers3

1

What about trying it in two steps?

<set-variable variableName="result" value="#[json:ADT_A01/PID/PID.3/CX.1]" />
<set-variable variableName="result" value="#[result.substring(0,4)]#[result.substring(5,7)]" />
Ryan Hoegg
  • 2,415
  • 2
  • 14
  • 15
  • Just trying to wrap my head around MEL, [here](http://www.mulesoft.org/documentation/download/attachments/122752116/refcard-mel.pdf?version=1&modificationDate=1404857929206) it is mentioned that MEL has no explicit for JSON processing. The syntax you guys are using is the old expression evaluation which is deprecated since Mule 3.3, need you to confirm my understanding please – Sudarshan May 07 '15 at 22:21
  • 1
    You are correct. Another way to do this without the deprecated JSON expression evaluator is to use json-to-object-transformer to convert to lists and maps, and use conventional object and property navigation. – Ryan Hoegg May 08 '15 at 21:44
1

As noted in the comments in @Ryan Hoegg answer, the JSON expression evaluator has been deprecated since Mule 3.3 and hence the best way to do this would be to use a json to object transformer

<json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.HashMap"/>

and then use conventional MEL to traverse the Map

Sudarshan
  • 8,574
  • 11
  • 52
  • 74
0

JsonPath expression are depreciated for now and you will even not get enough document on it for doing ..
So, currently you need to use either :- <json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object" />
or <json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object" />
or even <json:json-to-object-transformer returnClass="java.util.List" doc:name="JSON to Object" /> to extract data from JSON depending on the JSON data

Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81