Covered in this article
Jsonata component pages
Created on Updated on
Jsonata component

Jsonata component

Dedicated data transformation component.

Latest changelog

1.0.4 (May 19, 2019)

  • Update sailor version to 2.6.7
  • Fix codestyle

To see the full changelog please use the following link.

Authentication

This component requires no authentication.

How it works

This component takes the incoming message body and applies the configured JSONata transformation on it. It uses a fact that JSONata expression is a superset of JSON document so that by default any valid JSON document is a valid JSONata expression.

For example let’s take this sample incoming message body:

{
  "Account": {
    "Account Name": "Firefly",
    "Order": [
      {
        "OrderID": "order103",
        "Product": [
          {
            "Product Name": "Bowler Hat",
            "ProductID": 858383,
            "SKU": "0406654608",
            "Description": {
              "Colour": "Purple",
              "Width": 300,
              "Height": 200,
              "Depth": 210,
              "Weight": 0.75
            },
            "Price": 34.45,
            "Quantity": 2
          },
          {
            "Product Name": "Trilby hat",
            "ProductID": 858236,
            "SKU": "0406634348",
            "Description": {
              "Colour": "Orange",
              "Width": 300,
              "Height": 200,
              "Depth": 210,
              "Weight": 0.6
            },
            "Price": 21.67,
            "Quantity": 1
          }
        ]
      }
    ]
  }
}

You can use following JSONata expressions to transform it:

{
	"account": Account."Account Name",
	"orderCount" : $count(Account.Order)
}

result of that transofrmation will be the following JSON document (jsonata link):

{
  "account": "Firefly",
  "orderCount": 1
}

I hope you’ve got the idea. Now you can also do something more complicated, like this array-to-array transformation:

{
    "account": Account."Account Name",
    "products": Account.Order.Product.({
    	"name": $."Product Name",
        "revenue": (Price * Quantity)
    }),
    "orderIDs": Account.Order[].(OrderID)
}

resulting in (jsonata link):

{
  "account": "Firefly",
  "products": [
    {
      "name": "Bowler Hat",
      "revenue": 68.9
    },
    {
      "name": "Trilby hat",
      "revenue": 21.67
    }
  ],
  "orderIDs": [
    "order103"
  ]
}

Triggers

This component has no trigger functions. This means it will not be accessible to select as a first component during the integration flow design.

Actions

  • Transform