hpandalai
hpandalai

Reputation: 458

Expression Component JSON parsing

I have 10 variables I need to set by parsing JSON payload like #[json:REQUEST_ID] etc. Can this be done thru an expression component all of the variables instead of using Set Variable one after the other. I am looking for how to parse a json payload within an expression component. Many Thanks.

Upvotes: 1

Views: 602

Answers (2)

Julio Cejas
Julio Cejas

Reputation: 573

You can use <message-properties-transformer> to simplify the handling of variables on the flow, for example:

<message-properties-transformer doc:name="Message Properties">
    <add-message-property key="variableName" value="#[payload.from]" />         
    <add-message-property key="prmts" value="#[org.apache.commons.lang.StringUtils.split(payload.parameters, ';')]" />                  
</message-properties-transformer>

I hope I can help you.

Upvotes: 0

Ryan Hoegg
Ryan Hoegg

Reputation: 2475

I'd prefer an enricher to a message-properties-transformer here:

<enricher>
    <enrich target="#[variable:requestId] source="#[json:REQUEST_ID]" />
    <enrich target="#[variable:otherThing] source="#[json:OTHER_THING]" />
</enricher>

Upvotes: 0

Related Questions