Mule 4 Mulesoft Basics Mulesoft Tutorial

Mule – 4 DataWeave Functions – Part – 1


In DataWeave 2.0 functions are categorized into different modules.

  1. Core (dw::Core)
  2. Arrays (dw::core::Arrays)
  3. Binaries (dw::core::Binaries)
  4. Encryption (dw::Crypto)
  5. Diff (dw::util::Diff)
  6. Objects (dw::core::Objects)
  7. Runtime (dw::Runtime)
  8. Strings (dw::core::Strings)
  9. System (dw::System)
  10. URL (dw::core::URL)

Functions defined in Core (dw::Core) module are imported automatically into your DataWeave scripts. To use other modules, we need to import them by adding the import directive to the head of DataWeave script, for example:

import dw::core::Strings

import dasherize, underscore from dw::core::Strings

import * from dw::core::Strings

Sample Payload:
{
"firstName" : "Murali",
"lastName" : "Krishna",
"age" : "26",
“age” : ”26”
}

1. Core (dw::Core)

Below are the DataWeave 2 core functions:

++ , –, abs, avg, ceil, contains, daysBetween, distinctBy, endsWith, filter, IsBlank, joinBy, min, max etc….

result : [0, 1, 2] ++ [“a”, “b”, “c”] will gives us “result” : “[0, 1, 2, “a”, “b”, “c”]”

result : [0, 1, 1, 2] — [1,2] will gives us “result” : “[0]”

result : abs(-20) will gives us “result” : 20

average : avg([1, 1000]) will gives us “average” : 500.5

value : ceil(1.5) will gives us “value” : 2

result : payload contains “Krish” will gives us “result” : true

days: daysBetween(“2016-10-01T23:57:59-03:00”, “2017-10-01T23:57:59-03:00”) will gives us “days”: 365

age : payload distinctBy $ will gives us  :

 {

“firstName” : “Murali”,

“lastName” : “Krishna”,

“age” : ”26”

}

a: “Murali” endsWith “li” will gives us “a” : true

a: [1, 2, 3, 4, 5] filter($ > 2) will gives us “a” : [3,4,5]

empty: isBlank(“”) will gives us “empty” : true

aa: [“a”,”b”,”c”] joinBy “-” will gives us “a” : “a-b-c”

a: min([1, 1000]) will gives us “a” : 1

a: max([1, 1000]) will gives us “a” : 1000

2.Arrays (dw::core::Arrays)

Arrays related functions in DataWeave are :

countBy, divideBy, every, some, sumBy

[1, 2, 3] countBy (($ mod 2) == 0) will gives us 1

[1,2,3,4,5] dw::core::Arrays::divideBy 2 will gives us :

[

[

1,

2

],

[

3,

4

],

[

5

]

]

 

[1,2,3,4] dw::core::Arrays::every ($ == 1) will gives us “false”

[1,2,3,4] dw::core::Arrays::some ($ == 1) will gives us “true”

[ { a: 1 }, { a: 2 }, { a: 3 } ] sumBy $.a will gives us “6”

3.Binaries (dw::core::Binaries)

Binary functions in DataWeave-2 are:

fromBase64, fromHex, toBase64, toHex

toBase64(fromBase64(12463730)) will gives us “12463730”

{ “binary”: fromHex(‘4D756C65’)} will gives us “binary” : “Mule”

{ “hex” : toHex(‘Mule’) } will gives us “hex” : “4D756C65”

4.Encryption (dw::Crypto)

Encryption functions in Dataweave – 2 are:

HMACBinary, HMACWith, MD5, SHA1, hashWith

{ “HMAC”: Crypto::HMACBinary((“aa” as Binary), (“aa” as Binary)) } will gives us :

“HMAC”: “\u0007£š±]\u00adÛ\u0006‰\u0006Ôsv:ý\u000b\u0016çÜð”

Crypto::MD5(“asd” as Binary) will gives us “7815696ecbf1c96e6894b779456d330e”

Crypto::SHA1(“dsasd” as Binary) will gives us “2fa183839c954e6366c206367c9be5864e4f4a65”

5.Diff (dw::util::Diff)

It calculates difference between two values and returns list of differences.

DataWeave Script:

%dw 2.0

import * from dw::util::Diff

output application/json

var a = { age: “Test” }

var b = { age: “Test2” }

a diff b

Output:

{

“matches”: false,

“diffs”: [

{

“expected”: “\”Test\””,

“actual”: “\”Test2\””,

“path”: “(root).age”

}

]

}

Note:

Rest of the things will proceed in Mule – 4 DataWeave Functions Part – 2 article


108 comments

  1. Interior Painter

    Hello there, just became alert to your blog through Google, and found that it is really informative. I’m gonna watch out for brussels. I will appreciate if you continue this in future. Many people will be benefited from your writing. Cheers!

  2. moving company near me

    Hello would you mind stating which blog platform you’re using? I’m looking to start my own blog soon but I’m having a hard time selecting between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I’m looking for something completely unique. P.S My apologies for being off-topic but I had to ask!

  3. best local moving company near me

    Greetings from California! I’m bored to death at work so I decided to browse your site on my iphone during lunch break. I love the info you provide here and can’t wait to take a look when I get home. I’m surprised at how quick your blog loaded on my mobile .. I’m not even using WIFI, just 3G .. Anyways, excellent blog!

  4. Beard Oil To Grow Hair Facial

    Hey there this is somewhat of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding skills so I wanted to get guidance from someone with experience. Any help would be enormously appreciated!

  5. Free Movies Sites Online

    Today, I went to the beach front with my children. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is totally off topic but I had to tell someone!

  6. Fallon Tigney

    Hay distintos softwares que permiten diseñar las piezas de tubo y enviarlos directamente a la máquina con sólo un click. Dentro de nuestro equipo de trabajo contamos con profesionales altamente cualificados que tienen una amplia experiencia en el sector. El grupo Egile XXI, al que pertenece Talleres Leorpe, cuenta con varias empresas de mecanizado de precisión, que trabajan principalmente para el sector aeronáutico, colaborando en muchos proyectos.

  7. Leslie Pirollo

    I am no longer sure where you are getting your information, but great topic. I must spend a while finding out more or figuring out more. Thank you for magnificent info I used to be in search of this info for my mission.

  8. Berberine Gummies 1200mg

    Hi there! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains. If you know of any please share. Many thanks!

  9. Pok Mahdi

    Fantastic goods from you, man. I’ve understand your stuff prior to and you’re just too excellent. I actually like what you’ve obtained right here, really like what you’re saying and the best way during which you assert it. You’re making it enjoyable and you still take care of to stay it sensible. I can’t wait to read far more from you. That is actually a great web site.

  10. arbitrage selling on amazon

    Hmm it seems like your website ate my first comment (it was super long) so I guess I’ll just sum it up what I submitted and say, I’m thoroughly enjoying your blog. I too am an aspiring blog writer but I’m still new to everything. Do you have any tips for inexperienced blog writers? I’d certainly appreciate it.

  11. This Site electrician near me free estimate

    Fantastic goods from you, man. I have understand your stuff previous to and you are just extremely great. I really like what you’ve acquired here, certainly like what you are stating and the way in which you say it. You make it enjoyable and you still take care of to keep it wise. I can’t wait to read far more from you. This is actually a terrific site.

  12. 24 hour plumber near me look at this web-site

    Hmm it appears like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I too am an aspiring blog writer but I’m still new to everything. Do you have any suggestions for beginner blog writers? I’d really appreciate it.

  13. More Info electrician contractor

    I liked up to you will obtain carried out proper here. The cartoon is tasteful, your authored material stylish. nevertheless, you command get got an impatience over that you want be turning in the following. unwell certainly come further formerly once more since precisely the same nearly a lot often inside case you defend this hike.

  14. Marian Sweatt

    I was just seeking this information for a while. After six hours of continuous Googleing, at last I got it in your site. I wonder what’s the lack of Google strategy that do not rank this kind of informative web sites in top of the list. Normally the top websites are full of garbage.

  15. Bandar Slot

    Do you have a spam problem on this site; I also am a blogger, and I was wanting to know your situation; many of us have created some nice methods and we are looking to trade strategies with others, why not shoot me an email if interested.

  16. Sindy Closs

    I’m not sure where you are geting your info, but good topic.I needs tto spend some tiime learning much more or understanding more.Thanks foor wonderful information I was looking for this info for my mission.

  17. Timmy Vaugh

    Exceptional post however , I was wanting to know if you could write a litte more on this topic? I’d be very thankful if you could elaborate a little bit further. Many thanks!

  18. Dorathy Mcandrews

    I simply want to say I’m all new to blogging and really savored this blog. Probably I’m want to bookmark your site . You absolutely have fantastic article content. Thanks a bunch for sharing with us your website page.

  19. Hans Konty

    I have learn several good stuff here. Certainly price bookmarking for revisiting. I wonder how a lot attempt you place to create this kind of magnificent informative website.

  20. Lila Sacavage

    Undeniably believe that which you said. Your favorite justification seemed to be on the net the simplest thing to be aware of. I say to you, I certainly get irked while people consider worries that they just do not know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side effect , people can take a signal. Will probably be back to get more. Thanks

  21. simon kontakt

    I think this is among the most vital information for me. And i am glad reading your article. But wanna remark on few general things, The web site style is wonderful, the articles is really excellent : D. Good job, cheers

  22. slim fast diet plan

    I am so thankful for this content. I should say that I concur on many of the key points you list here while additional points will probably necessitate some additional analysis, but nevertheless I can at least partially support your point of view.

  23. Cesar

    Hello there! This is my 1st comment here so I just wanted
    to give a quick shout out and tell you I truly enjoy reading through your blog posts.

    Can you recommend any other blogs/websites/forums that go over the same topics?
    Thanks a ton!

  24. dasdas

    Hello there, just became aware of your blog through Google, and found that it’s truly informative. I am going to watch out for brussels. I?ll be grateful if you continue this in future. Lots of people will be benefited from your writing. Cheers!

  25. Mckenzie

    We are a group of volunteers and starting a new scheme in our
    community. Your web site offered us with valuable info to work on. You’ve done an impressive job and our whole community will be thankful to you.

  26. Kristan

    Attractive section of content. I just stumbled upon your site and in accession capital to assert that I acquire actually enjoyed account your blog posts.

    Any way I will be subscribing to your augment and even I
    achievement you access consistently rapidly.

  27. Mollie

    Heya i’m for the first time here. I came across this board and I find It really helpful & it
    helped me out a lot. I am hoping to give one thing again and aid others such
    as you helped me.

  28. Susie

    Hey there this is somewhat of off topic but I was wondering if blogs use WYSIWYG editors
    or if you have to manually code with HTML. I’m starting a blog soon but have no coding expertise so I wanted to get guidance from
    someone with experience. Any help would be greatly appreciated!

  29. Johnette

    You can definitely see your skills in the work you write.
    The world hopes for more passionate writers like you who are not afraid to mention how they believe.

    At all times follow your heart.

  30. Anitra

    I’m gone to say to my little brother, that he should also visit this webpage on regular basis
    to obtain updated from most up-to-date information.

  31. Dewitt

    Hmm is anyone else encountering problems with the images on this blog loading?

    I’m trying to determine if its a problem on my end or if
    it’s the blog. Any feedback would be greatly
    appreciated.

  32. Dominik

    Can I simply just say what a comfort to uncover someone who genuinely knows what they’re talking about on the internet.
    You actually understand how to bring an issue to light and make it important.
    A lot more people really need to check this out
    and understand this side of your story. I can’t
    believe you are not more popular because you certainly
    have the gift.

  33. Tracey

    Hi there! I just wanted to ask if you ever have any issues
    with hackers? My last blog (wordpress) was hacked and I ended up losing a few months
    of hard work due to no back up. Do you have any solutions to protect
    against hackers?

  34. Arnoldo

    You’ve made some really good points there. I checked on the net to
    learn more about the issue and found most individuals will go along with your views on this site.

  35. Kai

    Hmm it looks like your blog ate my first comment (it was
    super long) so I guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying your blog.

    I as well am an aspiring blog writer but I’m still new to everything.
    Do you have any recommendations for inexperienced blog writers?

    I’d definitely appreciate it.

  36. private insta viewer

    Hey there, I think your blog might be having browser compatibility issues.

    When I look at your blog in Firefox, it looks fine but when opening
    in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that, fantastic
    blog!

  37. Stacie

    Hi there exceptional website! Does running a blog such as this
    require a great deal of work? I have very little knowledge of
    coding but I was hoping to start my own blog soon. Anyway,
    should you have any suggestions or tips for new blog owners please share.
    I understand this is off subject however I just needed to ask.
    Kudos!

  38. free v bucks apk download

    I love your blog.. very nice colors & theme.
    Did you create this website yourself or did you
    hire someone to do it for you? Plz answer back as I’m
    looking to create my own blog and would like to know where u got this from.
    thank you

  39. Andrew

    I love what you guys are up too. This sort of clever work and reporting!
    Keep up the very good works guys I’ve added you guys to my
    personal blogroll.

  40. Poppy

    It is appropriate time to make some plans for the future and
    it is time to be happy. I have read this post and if
    I could I wish to suggest you some interesting things or
    advice. Maybe you can write next articles referring to
    this article. I desire to read even more things about it!

  41. Darrel

    At this time it looks like Expression Engine is the best blogging platform
    available right now. (from what I’ve read) Is that what you’re using on your blog?

  42. why not try these out

    In now time, considering the fast chosen lifestyle that everyone leads, credit cards get this amazing demand throughout the economy. Persons from every field are using the credit card and people who aren’t using the credit cards have prepared to apply for even one. Thanks for sharing your ideas in credit cards.

  43. Pearlie

    My wife and i were really more than happy when Albert could carry out his basic research from your precious recommendations he received out of your site. It is now and again perplexing to simply choose to be making a gift of guidelines that many other people may have been making money from. And we all realize we have the blog owner to appreciate because of that. Most of the illustrations you made, the simple site menu, the relationships you will aid to engender – it’s all impressive, and it’s assisting our son in addition to our family recognize that the idea is fun, and that’s exceptionally mandatory. Thanks for all the pieces!

  44. funny post

    In these days of austerity and also relative anxiousness about taking on debt, most people balk against the idea of utilizing a credit card to make acquisition of merchandise or maybe pay for a vacation, preferring, instead to rely on this tried and trusted means of making payment – hard cash. However, if you have the cash there to make the purchase in whole, then, paradoxically, that’s the best time to use the credit cards for several factors.

  45. click to investigate

    In these days of austerity plus relative stress about incurring debt, some people balk resistant to the idea of using a credit card in order to make acquisition of merchandise or maybe pay for any occasion, preferring, instead to rely on the tried as well as trusted procedure for making repayment – hard cash. However, if you have the cash there to make the purchase fully, then, paradoxically, that’s the best time just to be able to use the credit card for several factors.

  46. try this out bizopsbusiness.com

    Thanks for these tips. One thing I additionally believe is that credit cards providing a 0 rate often attract consumers along with zero monthly interest, instant authorization and easy on the web balance transfers, but beware of the number one factor that will certainly void your own 0 easy streets annual percentage rate and as well as throw you out into the terrible house quickly.

  47. recommended you read bizopsbusiness.com

    These days of austerity and also relative anxiety about running into debt, many individuals balk contrary to the idea of utilizing a credit card to make purchase of merchandise or maybe pay for any occasion, preferring, instead to rely on the particular tried in addition to trusted way of making settlement – raw cash. However, in case you have the cash available to make the purchase in full, then, paradoxically, that’s the best time for them to use the cards for several causes.

  48. official site bizopsbusiness.com

    One thing is that one of the most widespread incentives for utilizing your credit card is a cash-back or rebate supply. Generally, you will get 1-5 back in various buying. Depending on the credit card, you may get 1 returning on most expenditures, and 5 back on expenditures made from convenience stores, gas stations, grocery stores in addition to ‘member merchants’.

  49. redirected here bizopsbusiness.com

    Thanks for these tips. One thing I also believe is always that credit cards offering a 0 apr often bait consumers in with zero rate, instant acceptance and easy internet balance transfers, but beware of the real factor that will probably void the 0 easy neighborhood annual percentage rate and to throw anybody out into the poor house quick.

  50. click over here bizopsbusiness.com

    Now, with all the fast lifestyle that everyone leads, credit cards get this amazing demand in the economy. Persons from every area are using the credit card and people who not using the credit cards have made arrangements to apply for even one. Thanks for spreading your ideas in credit cards.

  51. click here for info bizopsbusiness.com

    Thanks for these pointers. One thing I additionally believe is that credit cards offering a 0 rate often entice consumers with zero interest, instant authorization and easy on the net balance transfers, however beware of the most recognized factor that will void your current 0 easy street annual percentage rate and to throw one out into the very poor house rapid.

  52. recommended site bizopsbusiness.com

    Thanks for your tips. One thing really noticed is that banks as well as financial institutions know the spending behaviors of consumers and understand that many people max out their credit cards around the getaways. They properly take advantage of this real fact and then start flooding your inbox in addition to snail-mail box with hundreds of no-interest APR card offers soon after the holiday season finishes. Knowing that when you are like 98 of the American general public, you’ll get at the chance to consolidate financial debt and switch balances to 0 interest rates credit cards.

  53. go to these guys bizopsbusiness.com

    My spouse and i ended up being so more than happy Michael could conclude his investigations out of the ideas he obtained while using the weblog. It’s not at all simplistic to simply happen to be giving freely key points which often other people have been trying to sell. And we recognize we need you to thank for this. The specific illustrations you’ve made, the simple website navigation, the relationships your site assist to create – it’s all incredible, and it’s assisting our son and us consider that this matter is fun, which is truly vital. Thank you for the whole lot!

  54. Lauren Thier

    Thanks for these guidelines. One thing I should also believe is that credit cards giving a 0 rate often attract consumers with zero interest rate, instant approval and easy on-line balance transfers, nevertheless beware of the real factor that will void that 0 easy street annual percentage rate plus throw one out into the bad house quick.

  55. Simon Handren

    I truly love your blog.. Excellent colors & theme. Did you create this amazing site yourself? Please reply back as I’m trying to create my very own site and would love to know where you got this from or what the theme is named. Cheers!

  56. Tony Andebe

    I’m pretty pleased to discover this web site. I want to to thank you for your time for this particularly wonderful read!! I definitely appreciated every little bit of it and I have you bookmarked to look at new things in your web site.

Leave a Reply

Your email address will not be published.