Data Mapping in Kumologica
Tags: serverless, aws, lambda, microservices
Published: 2020-06-16 10:21:42


Data mapping is a key element in integration. Most of the prominent integration tools provide different capabilities for data mapping.

![](https://cdn-images-1.medium.com/max/2000/1*LA5ZlGTMlDlNbAyOa0po2A.png)

In this article I thought of sharing on how data mapping can be achieved in Kumologica . Kumologica is a tool and a runtime designed for building integration or microservice development on serverless architecture. 

For more info have a look into the following article : [https://dev.to/kumologica/kumologica-first-low-code-development-tool-for-aws-lambda-1ohm](https://dev.to/kumologica/kumologica-first-low-code-development-tool-for-aws-lambda-1ohm)
 
Kumologica uses JSONata as the base for data mapping. JSONata is a Lightweight query and transformation language for JSON data. It supports complex queries expression which can be achieved with minimal syntax and has a location path semantics of Xpath 3.1.

For more info on JSONata you may refer the following link. [https://jsonata.org/](https://jsonata.org/)

To understand the Kumologica data mapping lets create an API which will accept a JSON data as an API request which will be mapped to a new JSON data structure and provide as API response. The request JSON data will also be sorted in descending order when mapping is done. Kumologica data mapper node will achieve both mapping and sorting function together.

Now let’s get started.

**Pre-requisite**

1. Downloaded and Installed Kumologica Designer.(Required) [https://kumologica.com/download.html](https://kumologica.com/download.html)

1. Walkthrough on tutorial.(Optional) [https://medium.com/@kumologica](https://medium.com/@kumologica)

**Developing an API**

1. Open the Kumologica Designer and *create a new* project.

1. Drag and drop **EventListener** node from the palette on to the designer canvas.

1. Configure the **EventListener** node with the Source as *API Gateway. *Verb as *POST *and path as* /employee.*

1. Drag and drop an datamapper node from the palette on to the designer.

1. On the **Sample Input** section of the datamapper node paste the following

```
    [
       {
           "Candidate_Name" : "Arun",
           "Candidate_Age" :  "25"
     
       },
          {
           "Candidate_Name" : "John",
           "Candidate_Age" :  "32"
     
       },
       {
           "Candidate_Name" : "Sarah",
           "Candidate_Age" :  "22"
     
       },
          {
           "Candidate_Name" : "Harry",
           "Candidate_Age" :  "28"
     
       }

    ]
```

On the **Mapping** section of the datamapper node paste the following mapping expression.

    $sort(
       $map(
           msg,
           (
               function($l){
                   {
                       "EmpName" : $l.Candidate_Name,
                       "Emp_Age" : $l.Candidate_Age
       
                   }

    }
           )

    ),
       function($l,$r){$l.Emp_Age < $r.Emp_Age}
    )

On the Result section (Bottom) of the datamapper node you could see the resultant output that would be generated by the node after running the mapping expression against the sample input JSON data provided. Following is the resultant output .

    [
        {
            "EmpName": "Jhon",
            "Emp_Age": "32"
        },
        {
            "EmpName": "Harry",
            "Emp_Age": "28"
        },
        {
            "EmpName": "Arun",
            "Emp_Age": "25"
        },
        {
            "EmpName": "Sarah",
            "Emp_Age": "22"
        }
    ]

As you can see the *Result* output shown has mapped the JSON request to a new structure and also sorted the records in descending order.

6. Now Drag and drop the **EventListener End** node on to the canvas.

7. Open the settings for **EventListener End **and configure the payload as *msg.payload *and leave rest of the values as default.

8. Wire the EventListener node to Datamapper node and Datamapper node to EventListenerEnd node. The final flow would like as given below.

![Kumologica API flow](https://cdn-images-1.medium.com/max/2196/1*x9jSZMCz0EYCc-mXp8FDjw.png)*Kumologica API flow*

**Deployment**

Now let’s deploy the flow to AWS lambda.

Before deployment select the AWS profile under the cloud tab. Also ensure that your AWS profile selected is having *Kumologica Designer Role *associated. If proper role is not associated the flow will fail to deploy to AWS.

Set the trigger section under the cloud tab as given below

![API gateway trigger configuration under cloud tab](https://cdn-images-1.medium.com/max/2000/1*b4qzUFFELCM0_bUvFrYFrA.png)*API gateway trigger configuration under cloud tab*

Now Click **Deploy*** .*

Once the deployment is completed you will get the endpoint url to invoke the service from any of your favourite client. The url will look like as shown below.

[https://t7cq0rkdk.execute-api.ap-southeast-1.amazonaws.com/test/employee](https://t7cq0rkdk.execute-api.ap-southeast-2.amazonaws.com/test/employee)

**Conclusion**

The mapping mechanism in Kumologica was easy and follows function chaining which allows to build sophisticated query expressions with minimal syntax. The designer gives quick preview without deploying and running the whole flow which saves a lot of time. JSONata expression language looks more or less similar to Mulesoft Dataweave. So If you are familiar with dataweave then JSONata would require zero or minimal learning curve.

If you want to try out this application you can clone the repo using the below given Github url or import the flow json into your project workspace in designer.
[**ab73863/kumologica-datamapper**
*Sample flow to demonstrate kumologica datamapping. Contribute to ab73863/kumologica-datamapper development by creating…*github.com](https://github.com/ab73863/kumologica-datamapper.git)

**References**

[https://kumologica.com/](https://kumologica.com/)

[https://jsonata.org/](https://jsonata.org/)