User Defined Functions
Here is a example from Mule document:%dw 1.0 %output application/json %function toUser(user) { firstName: user.givenName, lastName: user.sn } --- { "user" : toUser({ givenName : "Annie", sn : "Point" }) }Output from the result:
{ "user": { "firstName": "Annie", "lastName": "Point" } }
Mule document did not provide much explanation. What does this function do?
%function toUser(user) { firstName: user.givenName, lastName: user.sn }First, we can see it declares the user object, which has {givenName, sn}. When we use the function in the body, we parse an object of user in the form of:
toUser({ givenName : "Annie", sn : "Point" })Where
{ givenName : "Annie", sn : "Point" }is an user object. This tell us how you can initialize an object and pass to a function.
Using Build-in Function: GroupBy
If we want to group object by attribute, we can groupBy and pluck together. Here is the simple Dataweave code:
%dw 1.0 %output application/json --- payload groupBy $.stateHere is the input data:
[ { "name": "John Smith", "street": "1234 JS Ln", "city": "Allen", "state": "TX", "zip": "75123" }, { "name": "Framk Chambers", "street": "1234 Colleage Rd", "city": "Stillwater", "state": "OK", "zip": "73001" }, { "name": "Robert Goll", "street": "1234 Bush Dr", "city": "Plano", "state": "TX", "zip": "75127" }, { "name": "Billie Chambers", "street": "1234 College Rd", "city": "Stillwater", "state": "OK", "zip": "73001" } ]And here is the output:
[ { "name": "John Smith" }, { "name": "Robert Goll" }, { "name": "Framk Chambers" }, { "name": "Billie Chambers" } ]
This was an excellent blog Mulesoft online training
ReplyDeleteExcellent post!very usefull information Mulesoft Online Training Hyderabad
ReplyDeleteawesome post presented by you..your writing style is fabulous and keep update with your blogs.
ReplyDeleteMulesoft online training bangalore
the blog showa detailed mulesoft datawave tutorial it is useful for basic Developers of mulesoft kindly update more Info about
ReplyDeletemulesoft. for updated information go with
mulesoft Online Training
For more online Trainings Go with
tableau online training
ServiceNow Online Training
Python Online Training
This was an excellent blog,your writing style is fabulous and keep update with your blogs.
ReplyDeleteBig Data Hadoop online Course
It is nice blog Thank you porovide importent information and i am searching for same information to save my time thank you given mulesoft training. get more...
ReplyDeleteios Online Training
ReplyDeletethe blog is good and Interactive it is about MuleSoft Dataweave Tutorial: Part II - Functions it is useful for students and Mulesoft Developers for more updates on Mulesoft mulesoft Online course
Good post and great approach. I am pleased to visit and very useful articles here. I hope you keep doing more sharing the post to the readers.
ReplyDeleteLinux Training in Chennai
Linux Certification
Social Media Marketing Courses in Chennai
Pega Training in Chennai
Oracle Training in Chennai
Tableau Training in Chennai
Unix Training in Chennai
Excel Training in Chennai
Linux Training in Tambaram
Linux Training in OMR
This is most informative and also this post most user friendly and super navigation to all posts. Thank you so much for giving this information to me.mulesoft training in bangalore
ReplyDeleteThank you for sharing the valuable information.
ReplyDeletemulesoft course | mulesoft course online