Skip to content

4TT1L4/DataweaveCheatSheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 

Repository files navigation

Dataweave Cheatsheet (v1.0)

Reference: https://docs.mulesoft.com/mule-user-guide/v/3.9/dataweave

$$: key / index

$: value

@: Create or reference XML attribute

%output application/dw: Outputs the cannonical datamodel of DataWeave

Object:

{
  key: "value"
}

Array:

%dw 1.0
%output application/json
---
[ "elem1", "elem2", "elem3" ]

Map operator:

%dw 1.0
%output application/json
---
shirts: payload map {
        size: upper $.size,
        description: $.description,
        count: $.count
}

Constants and functions (%var):

%dw 1.0
%var prefix = 'The destination is: '
%var append = (param1, param2) ->  param1 ++ param2
%var createFlightCodeElement = (code) -> flightCode: code
%var createDestinationCodeElement = (dest) -> destinationCode: dest
%output application/xml
---
flights: {(payload map {
	flight @(flightCode: $.code):
	{	
		destination: append(prefix, $.destination),
        code: createFlightCodeElement($.code),
        dest: createDestinationCodeElement($.destination)
	}
 })
}

XML attribute in output

Input Transformation Output
[{
	"ID": 1,
	"code": "ER38sd",
	"destination": "SFO",
	"plane": {
		"type": "Boeing 737",
		"totalSeats": 150
	}
}, {
	"ID": 2,
	"code": "ER45if",
	"destination": "LAX",
	"plane": {
		"type": "Boeing 777",
		"totalSeats": 300
	}
}]
%dw 1.0
%output application/xml
---
flights: {(payload map {
	flight @(flightCode: $.code):
	{	
		destination: $.destination
	}
 })
}
<?xml version='1.0' encoding='windows-1252'?>
<flights>
  <flight flightCode="ER38sd">
    <destination>SFO</destination>
  </flight>
  <flight flightCode="ER45if">
    <destination>LAX</destination>
  </flight>
</flights>

Item index in the output ("$$")

Input Transformation Output
[{
	"ID": 1,
	"code": "ER38sd",
	"destination": "SFO",
	"plane": {
		"type": "Boeing 737",
		"totalSeats": 150
	}
}, {
	"ID": 2,
	"code": "ER45if",
	"destination": "LAX",
	"plane": {
		"type": "Boeing 777",
		"totalSeats": 300
	}
}]
%dw 1.0
%output application/xml
---
flights: {(payload map {
	flight @(index: $$):
	{	
		code: $.code
	}
})
}
<?xml version='1.0' encoding='windows-1252'?>
<flights>
  <flight index="0">
    <code>ER38sd</code>
  </flight>
  <flight index="1">
    <code>ER45if</code>
  </flight>
</flights>

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages