Skip to main content

JSONata Component

Transform data using the JSONata query and transformation language

Component key: jsonata


JSONata is a query and transformation language. This component takes data and a JSONata expression as input, and returns transformed data based on the expression. JSONata is helpful when you have a predictable data structure as an input, and you want to output a modified data structure. JSONata includes common functions you might execute on a data set - things like map, filter, sort, sum, string.split (the list goes on).

For example, suppose you had data that read:

{  "example": [{ "value": 4 }, { "value": 7 }, { "value": 13 }]}

If you applied a JSONata expression that read $sum(example.value) to this data, 24 would be returned because example.value generates an array of [4,7,13], and $sum finds the sum of those values.

You can find documentation and examples of JSONata expressions and functions on JSONata's documentation.

When to use the Code component instead

The JSONata component is helpful for data transformations, but if you are already comfortable with JavaScript or would like more flexibility in your data transformation, check out the code component instead.

Testing JSONata Expressions#

JSONata provides an incredibly useful JSONata test environment where you can try out expressions against data sets. This tool gives you a tight feedback loop, so you can test expressions quickly before pasting them into a JSONata step of an integration.

Some JSONata Examples#

Here are a couple examples that show off how to use JSONata expressions to process data:

Concatenating and Filtering Data#

In this example, a large block of information about a user is input. The JSONata expression concatenates the user's first and last name, and uses JSONata predicates to filter for the user's mobile phone number:

{  "name": FirstName & " " & Surname,  "mobile": Phone[type = "mobile"].number}

Using Built-in JSONata Functions#

In this example, information about a point-of-sale account lists an account name and an array of orders for several products. The expression uses the built-in $sum and $map functions to generate an object containing account name and an array of orders with the total owed for each order.

{  "Account": Account.`Account Name`,  "Orders": [    $map(Account.Order, function($v){      {        "id": $v.OrderID,        "total": $sum($map($v.Product, function($p) {          $p.Price * $p.Quantity        }))      }    })  ]}



Transform data using JSONata | key: transform

/ Required
This is an object with properties to feed into the JSONata expression.
{  "example": [    {      "value": 4    },    {      "value": 7    },    {      "value": 13    }  ]}
/ Required
A JSONata expression used to generate a string.