Search code examples
mulemule-eldataweave

Access Json element in Flow Variable - Mule 3.7


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


Solution

  • 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