# Transformation Nodes

# Node: 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

# Node: Form Data

Node transforms payload from multipart MIME type of content type form-data into json. It is useful when building flow that is backing html form and can only receive form-data content type.

All form fields will by transformed into string json fields in "key": "value" format.

All received files are stored in array of files with following details:

  • filename - the name of the file
  • content - the content of the file, Buffer: for example {"type": "Buffer", "data": [23,23,34,57]}
  • contentType - the type of file, for example image/png, application/json
  • encoding - the file encoding, for example 7bit
  • fieldname - the name of form's field for this file

# Node: 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

# Node: 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

# Node: 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

# Node: 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.

# Properties

  • Operation
    • 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.
    • Delete - Delete a 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.

Variables can be accessed inside the datamapper node using the expression vars.variablename and environment variable can be accessed using the expression env.variablename.

Payload can be accessed inside the datamapper using the expression msg.payload.

The mapping logic can be tested inside the datamapper editor using your sample payload. In this way you get the immediate result of your mapping logic under the Result panel of datamapper editor.

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

# Node: Function

TIP

The new access option for variables,message properties and environment variables are available only from Kumologica Designer version 2.1.3 and above.

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.mykey. Similarly a variable can be set using vars.mykey = 'somevalue'. A message can be accessed in function node using msg.mykey and can be set using msg.mykey = "myvalue". An environment variable can be accessed using env.key. The node doesn't provide the option for modifying the environment variable.

WARNING

It is strongly recommended not to use the following methods to access the variables,message properties and environment variables as they are going to be deprecated soon.

  • For accessing variable - $vars.get("key")
  • For setting variable - $vars.set("key","value")
  • For setting msg property - $msg.set("key","value")
  • For accessing msg property - $msg.get("key")
  • For accessing env variable - $env.get("key")

# Example

How to implement a custom logic using function node

# 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: [[msg.payload]]! will replace msg.payload 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 [[[msg.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.

Any variable stored in msg. can be used in template.

# Example

How to construct a dynamic html content using template node