JSLT

Discover more about the JSLT connector and how to use it on the Digibee Integration Platform.

The JSLT connector allows manipulation of a JSON using JSLT, a language for JSON processing and querying. For more information, see the official documentation on Github.

The connector is useful to perform several actions, such as:

  • Modify the structure of a JSON and keep its values.

  • Add, extract, and remove data from a JSON.

  • Sort the structure of a JSON.

  • Modify the values contained in a JSON through functions, such as text manipulation, mathematical calculations, conversions between data types, among others.

  • Access and manipulate data from arrays.

Parameters

Take a look at the configuration parameters for the connector. Parameters supported by Double Braces expressions are marked with (DB).

General tab

Parameter
Description
Default value
Data type

Payload (DB)

The JSON content to be manipulated.

{{ message.payload }}

JSON

JSLT

The JSLT declaration to be executed.

{ *: . }

JSON

Fail On Error

If enabled, interrupts the pipeline execution when an error occurs. If disabled, execution continues, but the "success" property will be set to false.

False

Boolean

Raw Mode

If this option is active, the JSLT expression can dynamically incorporate values using Double Braces ({{ }}) for entire expressions, object keys, or object values. This enables more flexible and dynamic transformations.

Important: When using Double Braces for a JSON key within the jsltExpr and Raw Mode is enabled, you must escape the key. For example, to dynamically use myKey as a key, you would write "{ \"{{message.myKey}}\": .value }".

False

Boolean

The connector doesn’t support JSLT import statements.

Documentation tab

Parameter
Description
Default value
Data type

Documentation

Optional field to describe the connector configuration and any relevant business rules.

N/A

String

JSLT expression examples

Simple data transpose

Payload

{
  "id" : "w23q7ca1-8729-24923-922b-1c0517ddffjf1",
  "type" : "component",
  "prefix": "jslt",
  "myString": "test",
  "myArray": [ 1, 2, 3, 4],
  "boolean": true
}

JSLT

{
  "uuid": .id,
  "obj": {
   "key-1": .type,
   "key-2": .prefix
  },
  * - myString, myArray, id: .
}

Output

{
  "uuid" : "w23q7ca1-8729-24923-922b-1c0517ddffjf1",
  "obj" : {
    "key-1" : "component",
    "key-2" : "jslt"
  },
  "type" : "component",
  "prefix" : "jslt",
  "boolean" : true
}

JSLT Native functions

The example below represents some of the available JSLT native functions. For more information about it and the complete list of functions, visit the Github documentation.

Payload

{
  "id" : "w23q7ca1-8729-24923-922b-1c0517ddffjf1",
  "type" : "component",
  "prefix": "jslt",
  "myString": "TEST",
  "myArray": [ 1, 2, 3, 4],
  "boolean": true
}

JSLT

{
  "uuid": split(.id, "-"),
  "obj": {
   "key-1": uppercase(.type),
   "key-2": join(.myArray, lowercase(.myString))
  },
  * : .
}

Output

{
  "uuid" : [ "w23q7ca1", "8729", "24923", "922b", "1c0517ddffjf1" ],
  "obj" : {
    "key-1" : "COMPONENT",
    "key-2" : "1test2test3test4"
  },
  "id" : "w23q7ca1-8729-24923-922b-1c0517ddffjf1",
  "type" : "component",
  "prefix" : "jslt",
  "myString" : "TEST",
  "myArray" : [ 1, 2, 3, 4 ],
  "boolean" : true
}

Variables and custom functions

Payload

{
  "id" : "w23q7ca1-8729-24923-922b-1c0517ddffjf1",
  "s1": "jslt",
  "s2": "component"
}

JSLT

let splitted = split(.id, "-")
let size = size($splitted)

def concat(s1, s2)
  if ($s1 != null)
    $s1 + "___" + $s2
  else
    ""

{
  "variables": $splitted,
  "size": $size,
  "customFunction": concat(.s1, .s2)
}

Output

{
  "variables": [
    "w23q7ca1",
    "8729",
    "24923",
    "922b",
    "1c0517ddffjf1"
  ],
  "size": 5,
  "customFunction": "jslt___component"
}

If and For Operators

Payload

{
  "id" : "w23q7ca1-8729-24923-922b-1c0517ddffjf1",
  "status": true
}

JSLT

let aux = split(.id, "-")

def concat(string1, string2)
   $string1 + "-" + $string2

{
  "forResult": [for ($aux) concat("test", .)],
  "ifResult": if (.status)
                 size(.id)
              else
                 0
}

Output

{
  "forResult" : [ "test-w23q7ca1", "test-8729", "test-24923", "test-922b", "test-1c0517ddffjf1" ],
  "ifResult" : 38
}

Dynamic expressions with Raw Mode

When Raw Mode is enabled, you can dynamically construct parts of your JSLT expression using Double Braces ({{ }}).

Complete dynamic expression

This example shows how to use a complete JSLT expression passed dynamically through the payload.

Parameters

  • Payload: {{ message.payload }}

  • JSLT: {{ message.expression }}

  • Raw Mode: true

Input Payload

{
  "payload": {
    "id" : "123456",
    "type": "String",
    "object": {
      "nested": "true"
    },
    "array": [
      99, 88, 77, 66, 55
    ]
  },
  "expression": "{  \\"code\\" : .id,  \\"boolean\\": .object.nested,  \\"element\\": .array[3],  \\"range\\": . array[0 : 2],   *: .}"
}

Output

{
  "code": "123456",
  "boolean": "true",
  "element": 66,
  "range": [ 99, 88 ],
  "id": "123456",
  "type": "String",
  "object": {
    "nested": "true"
  },
  "array": [ 99, 88, 77, 66, 55 ]
}
Dynamic object key

This example demonstrates how to dynamically set an object key within the JSLT expression. Note the escaped double quotes for the dynamic key.

Parameters

  • Payload: {{ message.payload }}

  • JSLT: { "code" : .id, {{ message.key }}: .object.nested, "element": .array[3], "range": . array[0 : 2], *: .}

  • Raw Mode: true

Input payload

{
  "payload": {
    "id" : "123456",
    "type": "String",
    "object": {
      "nested": "true"
    },
    "array": [
      99, 88, 77, 66, 55
    ]
  },
  "key": "\"boolean\""
}

Output

{
  "code": "123456",
  "boolean": "true",
  "element": 66,
  "range": [ 99, 88 ],
  "id": "123456",
  "type": "String",
  "object": {
    "nested": "true"
  },
  "array": [ 99, 88, 77, 66, 55 ]
}
Dynamic object value

This example shows how to dynamically set an object value within the JSLT expression.

Parameters

  • Payload: {{ message.payload }}

  • JSLT: { "code" : .id, "boolean": {{ message.value }}, "element": .array[3], "range": . array[0 : 2], *: .}

  • Raw Mode: true

Input payload

{
  "payload": {
    "id" : "123456",
    "type": "String",
    "object": {
      "nested": "true"
    },
    "array": [
      99, 88, 77, 66, 55
    ]
  },
  "value": ".object.nested"
}

Output

{
  "code": "123456",
  "boolean": "true",
  "element": 66,
  "range": [ 99, 88 ],
  "id": "123456",
  "type": "String",
  "object": {
    "nested": "true"
  },
  "array": [ 99, 88, 77, 66, 55 ]
}
Dynamic object key and value

This example demonstrates using Double Braces for both a dynamic key-value pair (*: .) within the JSLT expression.

Parameters

  • Payload: {{ message.payload }}

  • JSLT: { "code" : .id, "boolean": {{ message.value }}, "element": .array[3], "range": . array[0 : 2], {{ message.keyAndValue }}}

  • Raw Mode: true

Input payload

{
  "payload": {
    "id" : "123456",
    "type": "String",
    "object": {
      "nested": "true"
    },
    "array": [
      99, 88, 77, 66, 55
    ]
  },
  "value": ".object.nested",
  "keyAndValue": "*:."
}

Output

{
  "code": "123456",
  "boolean": "true",
  "element": 66,
  "range": [ 99, 88 ],
  "id": "123456",
  "type": "String",
  "object": {
    "nested": "true"
  },
  "array": [ 99, 88, 77, 66, 55 ]
}

Last updated

Was this helpful?