# Transformation Nodes

# CSV

The CSV node generate valid CSV output from a message containing key/value pairs of data. The CSV node can be used to generate well-formatted CSV strings. The CSV has been configured with the desired column names and uses the corresponding object properties to fill in those columns. The resulting message contains the well-formatted CSV string for that single row of data - including a newline character at the end.

Example:

How to convert a message to CSV data format

# JSON

The JSON node can be used to convert between javascript object and JSON string .The JSON node will, by default, detect what it is being given to convert. It can also be configured to ensure the property is a given type. For example if your flow could receive either JSON or an Object, the JSON node can be configured to ensure the property is an Object.

Example:

How to convert a message to JSON data format

# XML

The XML node can convert a message property between an XML string and the JavaScript object it represents.When a particular XML output format is required, it can be easier to start by injecting that into the XML node to see the necessary JavaScript object required to generate it when fed back the other way.

Example:

How to convert a message to XML data format

# YAML

The YAML node can convert a message property between a YAML string and the JavaScript object it represents. It can also convert a JavaScript object to a YAML string.

Example:

How to convert a message to YAML data format

# Set Property

The Set Property node can be used to modify a message’s properties and set context properties without having to resort to a Function node.

The node can be configured with multiple operations that are applied in order. The available operations are as follows.

Set set a property. The value can be a variety of different types, or can be taken from an existing message or context property.

Change Search and replace parts of a message property.

Move Move or rename a property.

Delete Delete a property.

Example: How to use a Set Property node.

# Datamapper

The datamapper node can be used for data transformation in JSON format. It gives all the flexibility for mapping the json fields and manipulating the fields with custom logics .

The node is based on JSONata transformation query language. It supports sophisticated query expressions with minimal syntax. Has Built in operators and functions for manipulating and combining data Can create user-defined functions.

TIP

Input payload to the datamapper must be a JSON. For more details related to JSONata language, refer the following link https://docs.jsonata.org/overview.html

Example:

How to do data mapping between two different payloads using datamapper

# Function

The Function node allows JavaScript code to be run against the messages that are passed through it.

The message is passed in as an object called msg. By convention it will have a msg.payload property containing the body of the message.

A variable can be accessed in function node using $vars.get("key"). Similarly a variable can be set using $vars.set("key","value"). A message can be accessed in function node using $msg.get("key") and can be set using $msg.set("key","value"). An environment variable can be accessed using $env.get("key"). The node doesn't provide the option for modifying the environment variable.

Example :

How to implement a custom logic using function node

# Template

The Template node can be used to generate text using a message’s properties to fill out a template.

It uses the Mustache templating language to generate the result. For example, a template of: This is the payload: [[payload]] ! . Will replace with the value of the message’s payload property. By default, Mustache will replace certain characters with their HTML escape codes. To stop that happening, you can use triple braces: v-pre [[[payload]]].The node will set the configured message or context property with the result of the template. If the template generates valid JSON or YAML content, it can be configured to parse the result to the corresponding JavaScript Object.

Example :

How to construct a dynamic html content using template node