DataMapper
Overview
The Kaoto DataMapper is a visual data mapping tool that allows you to create and manage data transformations within your Camel routes. It provides a user-friendly interface to define how data should be transformed from a source format to a target format, using drag-and-drop functionality and XPath expressions.
The DataMapper supports both XML and JSON schema for rendering the data structure. For both XML and JSON data, it internally generates a single XSLT step to perform configured data mappings at runtime. For JSON data, it leverages the json-to-xml() and xml-to-json() functions available in XSLT 3.0 to handle JSON transformations. While you can consume multiple XML/JSON documents using Camel Variables and/or Message Headers which are mapped to transformation parameters, the output is only a Camel Message Body.
Currently Kaoto DataMapper is only supported inside the Visual Studio Code extension as a technical preview feature. In the future we will aim to bring this functionality also to the pure web version of Kaoto.

Example Data Mappings
In addition to the regular Camel steps, Kaoto supports a Kaoto DataMapper step to be placed in the Camel Route. The Kaoto DataMapper step provides a graphical user interface to create data mappings inside the Camel Route.
Adding a DataMapper step
Add a Kaoto DataMapper step in your Camel route. When you
Append,PrependorReplacea step in the Kaoto Design view, you can find the Kaoto DataMapper step in the catalog.
DataMapper Catalog Tile
Click the added Kaoto DataMapper step in the Kaoto Design to open the config form.

Kaoto DataMapper step
In the config form, click the
Configurebutton.
DataMapper Configure button
This will open the visual DataMapper editor.

Blank DataMapper UI
Source and Target
In the DataMapper editor, you can see a Source section at the left and a Target section at the right side.

Source and Target
The Source section represents the input side of your mappings, where the DataMapper step reads the data from. This is mapped to the incoming Camel Message as well as possible Camel Variables.
The Target section represents the output side of your mappings, where the DataMapper step writes the data to. This is mapped to the outgoing Camel Message.
Parameters
The Parameters section inside the Source section is mapped to any of the incoming Camel Variables and Message Headers. For example, if there is an incoming Camel Variable orderSequence, you can consume it by adding a parameter orderSequence in the DataMapper Source/Parameters section.
Follow the below steps to add a parameter.
Click the plus + button on the right side of the
Parameterstitle.
Parameters
Now type the parameter name and click the check button on the right.

Add Parameter confirm
While Camel Exchange Properties are also mapped to parameters in the current camel-xslt-saxon implementation, after the Camel Variables have been introduced, it is no longer recommended to store application data in Camel Exchange Properties. We encourage to use Camel Variables instead.
Attaching Document Schema files
If any of Source Body, Target Body and/or Parameter(s) are structured data, you can attach a schema file and visualize the data structure in a tree style view. The DataMapper supports both XML Schema (XSD) and JSON Schema files.
If the data is not structured and just a primitive value, you don’t need to attach a schema file.
JSON schemas can be attached to Target Body and Parameter(s). However, it is currently not supported to attach JSON schema to Source Body.
Follow the below steps to attach a schema file.
Place schema file(s) inside the workspace directory.
Click
Attach a schemabutton in one of theSource Body,Target BodyorParameterssections.
Attach Schema
In the Attach schema modal, click the file button.

Schema File Upload
Select the schema file to attach.

Select schema
New! (XML only) Select the root element. The first element in the schema is selected by default. If the XML schema defines multiple top level elements and you want to use the other element than the first one, select one from the dropdown. This step is applicable only for XML. For JSON, skip to the next.

Select root element
Here is a demo screencast to choose a root element.
Click
Attachbutton.
Attach button
Now the document structure is rendered inside a tree.

Schema attached
JSON Schema Document
Kaoto DataMapper supports reading structured JSON parameter(s) and writing a JSON target body. If any of them is a structured JSON data and you have a JSON schema which defines the JSON data structure, you can attach the JSON schema file, render the document tree in DataMapper UI and create data mappings with it.
Follow the below steps to attach a JSON schema file.
Place schema file(s) inside the workspace directory.
Click
Attach a schemabutton in one of theTarget BodyorParameterssections.
Attach JSON Schema
In the Attach schema modal, click the file button.

JSON Schema File Upload
Select the schema file to attach.

Select JSON schema
If the file extension is
.json, it automatically switch the radio button below toJSON Schema. Otherwise, chooseJSON Schema. ClickAttachbutton.
Attach button
Now the JSON schema document structure is rendered inside a tree.

Schema attached
Here is a demo screencast for creating JSON mappings.
JSON schema document tree
Kaoto DataMapper uses XSLT 3.0 json-to-xml() and xml-to-json() functions to support JSON mappings. JSON document specific characteristics described in this section are mostly influenced by these XSLT 3.0 JSON support functions. Please visit XSLT 3.0 specification for more internal details.
When an XML schema document is rendered in DataMapper document tree, their element name and attribute name alone is shown as the field label. For JSON schema document, it is slightly different. Since JSON document field sometimes doesn’t have a name (anonymous), it uses field type as a primary field label.
map: object fieldarray: array fieldstring: string fieldnumber: number field
In addition to that, if the field has a name, it will show as a AccountId field label@key attribute following the field type.
For example, a string type field with a name AccountId will show the field label string [@key = AccountId].
An anonymous object field will show just Object field labelmap.
There is one thing that requires attention for JSON array field Collection fieldarray type field. The array type field indicates that its children are collection, in other words repeating field, but not the array type field itself.
For example, array type field with the name Item is rendered in DataMapper UI as following:

Here is an example JSON data mappings created in Kaoto DataMapper UI. It consumes JSON mappingsAccount and Cart structured JSON parameters as well as orderSequence primitive parameter, and create a ShipOrder JSON target body.
$Account-x to refer the parameter Account, not just $Account, but with a suffix -x.
Since Account parameter is a structured JSON, it is internally converted into XML with using json-to-xml. $Account-x is a variable which stores that XML document converted from JSON.
When data mappings are created through drag and drop, Kaoto DataMapper automatically handles that.
However when you edit the XPath expression manually, please keep this fact in mind.
With those JSON specific characteristics in mind, the rest of the way how to create mappings is same for XML and JSON. You can create mappings for XML to XML, XML to JSON, JSON to XML and JSON to JSON with Kaoto DataMapper. We will look into those in the following sections.
Creating simple mappings
Creating a mapping by dragging and dropping a field
When you perform drag and drop between the source and the target, a mapping is created and a line is drawn between the fields.
Example: Mapping the Name fields by dragging and dropping the source Name field on the target Name field.
Before: Drag name Drop name

Creating a mapping by typing an XPath expression
You can also create a mapping by entering a XPath expression.
Click the 3 dots context menu on the target field and choose
Add selector expression.
Add selector
Then enter the
XPathexpression.
Type xpath
Creating conditional mappings
The DataMapper supports creating 3 types of conditional mappings:
if- The mapping is created only when the specified condition is met.choose-when-otherwise- The mapping is created depending on how the condition is satisfied. If thewhenbranch condition is satisfied, thewhenbranch mapping is created. If nowhenbranch condition is satisfied, then theotherwisebranch mapping is created.for-each- The mapping is created for each item in the collection. Collection means multiple occurrences, which is often represented as an array.
Create a if mapping
Click the 3 dots context menu on the target section’s field. Then select
wrap with "if"to create a mapping.
3 dots menu

Wrap with if
Configure the
ifcondition. You can drag the source field and drop it into the input field to start writing a condition, or alternatively type everything manually.
Configure if condition
Configure the mapping by using drag and drop or by typing it manually.

Configure mapping
Create a choose-when-otherwise mapping
Click the 3 dots context menu on the target section’s field. Then select
wrap with "choose-when-otherwise"to create a mapping.
Wrap with choose-when-otherwise
Configure the
whencondition.
Configure when condition
Configure the mapping for the
whenbranch.
Configure when mapping
Configure the mapping for the
otherwisebranch.
Configure when mapping
If required, you can add one or more
whenbranches. To add anotherwhenbranch you can click the 3 dots menu on thechoosefield in theTargetsection and then selectAdd "when".
Configure when mapping

Configure when mapping
Create a for-each mapping
When a field is a collection field (means multiple occurrences, often represented as an array), you can create a Collection fieldfor-each mapping. The layer icon on the field indicates that it is a collection field.
Click the 3 dots context menu on the target section’s collection field. Then select
wrap with "for-each"to create a mapping.
Wrap with for-each
Configure the
for-eachcondition by specifying the source collection field to iterate over.
Configure for-each condition
Configure the mappings below. Note that the mapping field path is now a relative path from the collection field specified in the
for-eachcondition.
Configure for-each mappings
Create multiple mappings for a collection target field
A target collection field can have multiple mappings. For example, it can have multiple Add more mappingfor-each loops
to merge 2 different source collection fields into one target collection field. Once you create a first
mapping, you will see a place holder which has buttons to add more mappings.
After creating a first
for-eachmapping by following previous section, clickAdd Conditional Mappingin the placeholder below the addedfor-eachmapping
Add Conditional Mapping
Click
Wrap with "for-each"
Wrap with for-each
Map other source collection to the added
for-eachmapping
Map 2nd for-each
Create subsequent mappings

Map 2nd for-each children
Here is a demo screencast for merging 2 source collection fields with multiple for-each mappings.
Using XPath expression editor
The XPath editor is still under initial development and it currently supports only limited drag and drop. In future releases, more syntax assisting features will be added.
If you want to write something more in XPath expression rather than just a field path, you can launch the XPath expression editor and work with it. There is a pencil icon on the target field which launches the XPath expression editor when you click it.
Click the pencil button on a target field which has a mapping.

Launch XPath editor
This will open up the
XPatheditor.
XPath editor
You can then type in the editor at the right or drag a
Fieldfrom the left and drop onto the editor.
XPath editor: DnD fields
You can also drag and drop
XPathfunctions from theFunctiontab on the left side.
XPath editor: Functions
Drag the function and drop it onto the editor.

XPath editor: DnD functions
Once it’s completed, click the
Closebutton at the bottom left.
XPath editor: Close
Now you can see the new mapping in the tree view.

XPath editor: Done
Delete a mapping
To delete a mapping you can click the dustbin button next to the target field.

Delete a mapping
You then have to confirm the deletion by clicking the
Confirmbutton.
Confirm delete mapping
Delete a parameter
To delete a parameter, click the dustbin button next to the parameter.

Delete parameter
You then have to confirm the deletion by clicking the
Confirmbutton.
Delete parameter confirm
Detach a schema
Similar to attaching a schema you can also remove / detach a schema.
Click the
Detach schemabutton.
Detach schema button
Click the
Confirmbutton.
Detach schema confirm