Skip to main content

Run JSONata Code

Controlled node

Overview

The Run JSONata Code node evaluates JSONata expressions against input data. JSONata is a declarative query and transformation language for JSON data, allowing you to filter, transform, and extract specific values from complex data structures using a simple syntax.

This node is useful when you need to:

  • Extract specific fields from nested JSON objects
  • Filter arrays based on conditions
  • Transform data structures without writing complex JavaScript or Python code
  • Perform calculations or aggregations on JSON data

Inputs

InputTypeDescriptionDefault
RunEventTriggers the evaluation of the JSONata expression.-
CodeTextThe JSONata expression to evaluate. Supports JSONata syntax for querying and transforming JSON data.Empty string
DataDataThe input data (JSON object or array) to evaluate the expression against.-

Outputs

OutputTypeDescription
DoneEventFires when the node has finished evaluating the expression.
ResultDataContains the result of the JSONata evaluation. If the expression evaluates successfully, this contains the transformed data. If an error occurs, this contains an error object with a message.

Runtime Behavior

When the Run event is triggered, the node evaluates the JSONata expression provided in the Code input against the Data input. The evaluation is performed using the JSONata library, which supports:

  • Path expressions (e.g., name, address.city)
  • Array filtering (e.g., items[price > 10])
  • Array mapping (e.g., items.name)
  • Aggregations (e.g., $sum(items.price))
  • Conditional logic (e.g., price > 100 ? "expensive" : "cheap")

If the expression evaluates successfully, the result is output via the Result socket and the Done event fires. If the expression contains syntax errors or references non-existent paths, the Result will contain an error object with a descriptive message, and the Done event will still fire.

JSONata Syntax

For complex transformations, refer to the JSONata documentation. Common patterns include:

  • $ to reference the root object
  • * for wildcard matching
  • [] for array filtering and indexing
  • $map(), $filter(), $reduce() for functional programming operations

Example

Scenario: Extracting specific fields from a nested JSON object.

Input Data:

{
"users": [
{ "name": "Alice", "age": 30, "city": "New York" },
{ "name": "Bob", "age": 25, "city": "London" },
{ "name": "Charlie", "age": 35, "city": "New York" }
]
}

JSONata Code:

users[city = "New York"].name

Result Output:

["Alice", "Charlie"]

Workflow Usage:

  1. Connect a data source (e.g., a database query or API response) to the Data input
  2. Enter the JSONata expression in the Code input (or connect a Text node)
  3. Trigger the Run event to evaluate the expression
  4. Use the Result output in downstream nodes for further processing or display