1

Can we access a json element inside flow variables in Mule?

Eg: My flowVar value is { "Input1": { "Value1": "UNITED STATES" } }

How can I access the element 'Value1' using MEL in mule?

Thanks, ROA

ROA
  • 71
  • 1
  • 2
  • 8

4 Answers4

1

try the below expression,

#[json:/Input1/Value1]
Senthil c
  • 341
  • 2
  • 3
1

You can use dw function or json path expression to achieve this. examples:

[dw('payload.Request.name')]

[json:Request/name]

Community
  • 1
  • 1
Deep
  • 71
  • 7
0

Right answer is

#[flowVars.theVariable.Input1.Value1]

but get here you need a lot what to do. You have to create variable appropriately to match your description. Also name of the variable is missed but you need it anyway. Here is code

    <flow name="AccessFlowVariable">
        <poll doc:name="Poll">
            <fixed-frequency-scheduler frequency="10000000"/>
            <logger message="Flow started" level="INFO" doc:name="Logger"/>
        </poll>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-variable variableName="theVariable"><![CDATA[%dw 1.0
%output application/java
---
{ "Input1": { "Value1": "UNITED STATES" } }]]></dw:set-variable>
        </dw:transform-message>
        <logger message="#[flowVars.theVariable.Input1.Value1]" level="INFO" doc:name="Logger"/>
        <logger level="INFO" doc:name="Logger"/>
    </flow>

and here is result enter image description here

Alex
  • 4,457
  • 2
  • 20
  • 59
  • 2
    Your output on DW is Java, so the resulting type is (and is shown in your image above) is java.util.LinkedHashMap. So the dot notation works, I think he is asking that the flowVar is a string and not a hashmap. – Chad Gorshing Feb 03 '17 at 14:29
-1

"Can we access a json element inside flow variables in Mule?": Yes we can access json element inside flow variable.

"How can I access the element 'Value1' using MEL in mule?" Let says if you have stored this json in flow variable (xyz) then you can access it using the bellow syntax: flowVars.xyz.Input1.Value1

Abani Patra
  • 172
  • 3
  • 12