Questions tagged [dataweave]

The DataWeave Language is a powerful template engine that allows you to transform data to and from any kind of format (XML, CSV, JSON, Pojos, Maps, etc).

DataWeave is the MuleSoft expression language for accessing and transforming data that travels through a Mule app. DataWeave is tightly integrated with the Mule runtime engine, which runs the scripts and expressions in your Mule app.

DataWeave scripts act on data in the Mule event. Most commonly, you use it to access and transform data in the message payload. For example, after a component in your app retrieves data from one system, you can use DataWeave to modify and output selected fields in that data to a new data format, then use another component in your app to pass on that data to another system.

Full Reference

https://docs.mulesoft.com/mule-user-guide/v/3.7/dataweave-reference-documentation

https://docs.mulesoft.com/mule-runtime/4.2/dataweave

1845 questions
4
votes
4 answers

How to filter an array of JSON in Mule DataWeave

I am having a JSON like this : { "dcsId": "1184001100000000517", "marketCode": "US", "languageCode": "en-US", "profile": { "base": { "username": "arunima27", "activeInd": "R", "phone": [ { "activeInd": "Y", …
Mohit Mehrotra
  • 201
  • 1
  • 6
  • 12
4
votes
1 answer

How to replace special character using regex in Mule Dataweave transformation?

Suppose I have an XML file of details of employee such as id, name and address and now I want to convert it into JSON file and before the conversation I want to replace specified special character (- , /) with blank space in address field of json…
Aditya
  • 1,214
  • 7
  • 19
  • 29
4
votes
4 answers

Dataweave Error for Null nodes

I have done coding in dataweava as %dw 1.0 %input payload application/xml %output application/xml skipNullOn="everywhere" --- {((payload.*Order default []) map { Order:{ Channel:$.@EnterpriseCode, Code:$.@OrderNo, Status:$.@Status, …
Rohan Shinde
  • 131
  • 1
  • 4
  • 21
3
votes
1 answer

Why the "default" keyword acts like "try + catch / orElse" in some cases

I recently noticed an interesting behavior from the default keyword. It acts like try-catch or try-orElse in some situation. For example, if you try to execute the following script: %dw 2.0 output application/json --- ("ABC" as Number) default…
Harshank Bansal
  • 2,798
  • 2
  • 7
  • 22
3
votes
2 answers

DataWeave combine arrays in alternating order

If I have arrays [A,B,C]and [1,2,3] How can I combine them to be [A,1,B,2,C,3]
anonMule
  • 91
  • 2
3
votes
3 answers

Error trying to remove a namespace from an XML in Mule 4

I see the error like "Trying to write END_DOCUMENT when document has no root" while I replace all the payload env and xmlns with "". It throws error : Message : "Trying to write END_DOCUMENT when document has no root (ie. trying to…
codey_08
  • 249
  • 1
  • 11
3
votes
1 answer

Other ways to add default namespaces in Dataweave 2.0?

I recently figured out how to add default namespaces in XML by consulting this doc page. %dw 2.0 output application/xml var dns = {uri: "http://api.acme.com/customer", prefix: ""} as Namespace --- dns#customer: { dns#name: "Max", dns#city:…
George
  • 2,758
  • 12
  • 16
3
votes
3 answers

how to divide a String into defined parts using Dataweave in Mulesoft

I have a JSON object as below { "a" : "ABCDEFGHIJKL", "b" : "B" } here each field contains a string (all are of different sizes), I need to divide each field value (i.e string) by 4 and then make it a separate JSON object array and assigned it to…
Anurag Sharma
  • 780
  • 7
  • 31
3
votes
1 answer

How to assign value to a local variable in function in DataWeave

Hi i am getting an error saying Invalid input ' ', expected '}' for the do block. I am trying to create a concatenated String output fun getStreetAddress(address1 ,address2) = do { var addr1 = address1 var addr2 = address2 var finalAddress =…
VKP
  • 589
  • 1
  • 8
  • 34
3
votes
1 answer

Mule 4 : Dataweave 2.0 : is there any way we can have a filter condition in groupBy method that works similar to SQL GroupBY and Having?

Scenario : Given an input as below sampleArray , I will like to group all the students having a specific teacher. In DataWeave we have a method groupBy that allows us to group arrays specifying a string key. But here since…
Bibek Kr. Bazaz
  • 505
  • 10
  • 34
3
votes
2 answers

What is the quickest way to hide all sensitive data in a payload?

I have a very nested structure with sensitive data (SSN, passwords and so on). Is there a simple way of making all of those ---- so the content is hidden?
afelisatti
  • 2,770
  • 1
  • 13
  • 21
3
votes
2 answers

Mulesoft DataWeave: How to escape $ for quoted string

...I'm using Anypoint Studio 7.6 and writing in DataWeave 2.0 I cannot find the definitive way to include the $ (dollar sign) character in a quoted string. Here's what I tried: %dw 2.0 output application/dw var sign = "\u0024" // unicode dollar…
agentv
  • 739
  • 1
  • 9
  • 21
3
votes
2 answers

Key Existence in JSON Object (Mule 4)

I need to check the existence of a particular keyword in a JSON object and based on that, create a string. My sample dataweave 2.0 code is given below: %dw 2.0 output application/json var arr = { "ID": "100", "ProdId": "Prod", …
3
votes
2 answers

Compare a sub set array with a master array in Mule 4 (DW2.0)

I have a fixed elements array as : ['a', 'b', 'c', 'd'] This will be used as a base while comparing the input arrays (that can be subset of the master array) I get an input array of various combinations that may satisfy below set of scenarios: ['a',…
3
votes
1 answer

How to check what header is passed in the request configuration in mule

How can I find out whether the right header has been passed to my request or not. This is my header My request is failing…
HMT
  • 2,093
  • 1
  • 19
  • 51