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
2
votes
3 answers

Unflatten a JSON Object into nested JSON Object using Dataweave 2.0

I have this Flattened Object { "abc.def.ghi": "foo", "abc.def.jkl": "bar" } I want to write a dataweave to convert it into the original object, i.e. { "abc": { "def": { "ghi": "foo", "jkl": "bar" } } } I am trying to…
Harshank Bansal
  • 2,798
  • 2
  • 7
  • 22
2
votes
2 answers

Dataweave 2.0 - Create tree structured xml

I have json array of objects as below retrieved from database [ { "Projectid":"A1234","ProjectLvl":1,"desc":"A1234-desc"}, { "Projectid":"A1234.1","ProjectLvl":2,"desc":"A1234.1-desc"}, {…
ciba
  • 21
  • 2
2
votes
3 answers

DataWeave 2.0 how to build dynamically populated accumulator for reduce()

I'm trying to convert an array of strings into an object for which each member uses the string for a key, and initializes the value to 0. (Classic accumulator for Word Count, right?) Here's the style of the input data: %dw 2.0 output…
agentv
  • 739
  • 1
  • 9
  • 21
2
votes
1 answer

Transform EMS Queue message and insert into DB using Anypoint Studio

I am trying to listen and consume an EMS queue message and transform it to insert into a Database using Anypoint Studio platform. Below youn can find an example of the EMS queue message, and the structure of the target database table, as well as,…
2
votes
1 answer

Polymorphism in DW 2.0

I recently became aware of a generics-like notation to denote polymorphic types in DW 2.0. The example below %dw 2.0 output application/dw fun id1(a) = a fun id2(a: Any) = a fun id3(a: T) = a var id4 = (a: T) -> a --- { "d1": id1, …
George
  • 2,758
  • 12
  • 16
2
votes
3 answers

JSON object Ignore null

Im kinda new to MuleSoft and DataWeave and im trying to make a JSON Object with only not null values from another JSON object. Let's say this is my JSON array : { str1 : "String 1", str2 : "String 2", str3 : null, str4 : "String…
Fragan
  • 792
  • 10
  • 29
2
votes
1 answer

How to aggregate this data using Dataweave 2.0?

Take the following JSON. It is an array of objects. [ { "objects": [ { "saleItems": [ { "itemID": 1, "saleItemType": "Sale", "productCode": "072", "legacyProductCode":…
JackBruce
  • 23
  • 4
2
votes
2 answers

How to append fields in mule dataweave to existing json payload

Exisiting Json { a:1, b:2 } Add the field c:3 Final Output expected { a:1, b:2, c:3 }
user3440239
  • 78
  • 1
  • 5
2
votes
1 answer

Cannot coerce Array error while using map operator with XML data in mule 4?

I am getting the following error while using the map operator: org.mule.runtime.core.internal.message.ErrorBuilder$ErrorImplementation { description="Cannot coerce Array (org.mule.weave.v2.model.values.ArrayValue$IteratorArrayValue@22af825a) to…
HMT
  • 2,093
  • 1
  • 19
  • 51
2
votes
1 answer

Insert dynamic data based on array size in json mule 4

Existing JSON: { "name":"abc", "place": "äbc" } I have a separte array as below: [documentDetails:{ "name" : "doc1", "size" : "5" }, documentDetails:{ "name" : "doc1", "size" : "5" } ] Final JSON REQUIRED: { …
HMT
  • 2,093
  • 1
  • 19
  • 51
2
votes
0 answers

Mule Batch Job StepResults are Miselading

I was working with sample batchJob and figured something about the BatchStepResults. Created a simple application with small payload and BatchJob, with 3 BatchSteps . I have below payload and as per the batchJob the batchstep1 should process 4…
Learner
  • 157
  • 2
  • 17
2
votes
1 answer

How do you use variable as key in Dataweave

output application/json var name = vars.uname --- { vars.name: name, //-----> Here i am not able too retreive variable as key description: payload.text } for reference
Sri Rockz
  • 85
  • 1
  • 9
2
votes
2 answers

Unflatten an Array in Mulesoft Dataweave 2.0

I have a flat array of Customers, and could not find an appropriate Method (Way) to Unflatten it so that each Customer & his Age becomes Nested. INPUT { "1st Customer": "2216", "Age": "90", "2nd Customer": "2231", "Age": "90", "3rd Customer":…
2
votes
1 answer

Mule 4 : Memory Management : how to manage variables having huge data for example 300 Mb?

I am working on a mule application that fetches hundreds of thousands of records from database, do a map to change the structure of the incoming records using dataweave and insert the data in Salesforce. The steps I follow are: fetch all the…
Bibek Kr. Bazaz
  • 505
  • 10
  • 34
2
votes
2 answers

how to check whether the JSON recieved is empty/ nulll in mule 4

I am trying to check whether the json object is empty/ null but I am getting the following error: org.mule.runtime.core.api.expression.ExpressionRuntimeException: "Unable to parse empty input, while reading `obj` as Json. 1| ^ Trace: at main…
HMT
  • 2,093
  • 1
  • 19
  • 51