Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mule how to map Json values from payload to flow variables

Tags:

mule

I have a JDBC COnnector which retrieves values from the database and I have mapped them from object to JSON. Now I want to extract specific values from the json to flow variables. When I try to log #[message.payload], I get the full payload in the log which is in JSON format. However when I try to choose an attribute (eg. testattribute in json) #[message.payload.testattribute], I get mule expression error. How do I refer to the json values?

like image 635
user2758296 Avatar asked Jan 13 '23 10:01

user2758296


2 Answers

Once the payload is a JSON string, you can't extract anything from it anymore with an expression.

So either:

  • use MEL to extract the values into flow variables prior to convert the payload into JSON,
  • transform the JSON payload to either POJOs or Map/Lists, use MEL to extract the values into flow variables, and re-transform the payload back to JSON.
like image 153
David Dossot Avatar answered Feb 24 '23 02:02

David Dossot


If your requirement is to get the values from json data you can use a simple MEL expression like

#[json:<name of the node>] 

For example if you have an sample json data like this

{
"token" : 123,
"id" : 456,
"email" : "[email protected]",
"status" : "Success"
}

and if you want get the id from the data just use the below simple MEL.

#[json:'id']
like image 38
muralidhar gumma Avatar answered Feb 24 '23 04:02

muralidhar gumma