The functions were created to:

  • speed up the creation of your integrations even more

  • decrease the complexity of your pipelines

  • simplify data conversions and transformations during the flow of your pipelines

The JSON functions make operations in JSON objects and are available for components that support Double Braces expressions. To know how to provide information to the components using this resource, click here.

JSONPATH

This function in Double Braces returns parts of a determined document according to the sent expression.

Syntax

JSONPATH(value:string, expression:string) 

value: string

expression: string containing the expression to be recovered

Let's say you need to obtain part of a document by using expressions. You can do the following:

{
"test": {{ JSONPATH ({"store":{"book":[{"category":"reference","author":"Nigel Rees","title":"Sayings of the Century","price":8.95},{"category":"fiction","author":"Evelyn Waugh","title":"Sword of Honour","price":12.99},{"category":"fiction","author":"Herman Melville","title":"Moby Dick","isbn":"0-553-21311-3","price":8.99},{"category":"fiction","author":"J. R. R. Tolkien","title":"The Lord of the Rings","isbn":"0-395-19395-8","price":22.99}],"bicycle":{"color":"red","price":19.95}},"expensive":10}, "$.store.book[?(@.price > 10)]") }}
"test2": {{ JSONPATH (["aa","ss","","e"],"$.[0]" ) }}
}

The expected result will be:

{
"test": [{"category":"fiction","author":"Evelyn Waugh","title":"Sword of Honour","price":12.99},{"category":"fiction","author":"J. R. R. Tolkien","title":"The Lord of the Rings","isbn":"0-395-19395-8","price":22.99}]
"test2": "aa"
}

It's possible to use the functions that JSONPATH internally provides, such as:

  • min()

  • max()

  • avg()

  • stddev()

  • length

Example:

Let's say that an input array is received:

{
"numbers": [1,33,56,77.8,66,10475,665464,1,0.01]
}

And that you want to use the functions described above in the “expression” field:

{
"min": {{ JSONPATH(message.numbers, "$.min()") }},
"max": {{ JSONPATH(message.numbers, "$.max()") }},
"avg": {{ JSONPATH(message.numbers, "$.avg()") }},
"stddev": {{ JSONPATH(message.numbers, "$.stddev()") }},
"length": {{ JSONPATH(message.numbers, "$.length()") }}
}

The result will be:

{
"min": 0.01,
"max": 665464.0
"avg": 75130.42333333334,
"stddev": 208739.83034832493,
"length": 9
}

TOJSON

This function in Double Braces returns the JSON value from the received object.

Syntax

TOJSON(value:string)

value: string

Let's say you need to obtain the values of a JSON object. You can do the following:

{
"test": {{ TOJSON("aaS2fdeS") }}
"test2": {{ TOJSON(111) }}
"test3": {{ TOJSON("false") }}
"test4": {{ TOJSON([{"c":123}]) }}
"test5": {{ TOJSON({"a":123,"array":[1,2,3]}) }}
"test6": {{ TOJSON("{\"name\":\"John\",\"age\":31,\"city\":\"New York\"}") }}
"test7": {{ TOJSON(null) }}
}

The expected result will be:

{
"test": "aaS2fdeS"
"test2": 111
"test3": false
"test4": [{"c":123}]
"test5": {"a":123,"array":[1,2,3]}
"test6": {"name":"John","age":31,"city":"New York"}
"test2": null
}

UNESCAPEJSON

This function in Double Braces returns a JSON by removing the found escapes in the provided value.

Syntax

UNESCAPE(value:string)

value: string

Let's say you need to remove escape characters. You can do the following:

{
"test": {{ UNESCAPE ("{\\\"name\\\":\\\"John\\\",\\\"age\\\":31,\\\"city\\\":\\\"New York\\\"}") }}
}

The expected result will be:

{
"test": "{\"name\":\"John\",\"age\":31,\"city\":\"New York\"}"
}

GETELEMENTAT

This function allows you to capture a specific element from an array.

Syntax

GETELEMENTAT(array, index)

Let's say you need to capture the first element of the array below:

{
"data": [
{
"field": "value-1"
},
{
"field": "value-2"
},
{
"field": "value-3"
}
]
}

Capturing the element:

{
"element": {{ GETELEMENTAT(message.data, 0) }}
}

The result will be:

{
"element": {
"field": "value-1"
}
}

LASTELEMENT

This function allows you to capture the last element from an array.

Syntax

LASTELEMENT(array, index)

Let's say you need to capture the last element of the array below:

{
"data": [
{
"field": "value-1"
},
{
"field": "value-2"
},
{
"field": "value-3"
}
]
}

Capturing the element:

{
"element": {{ LASTELEMENT(message.data) }}
}

The result will be:

{
"element": {
"field": "value-3"
}
}

If the function receives an empty array, a null value will be returned.

NEWEMPTYOBJECT

This function allows you to create a new empty object.

Syntax

NEWEMPTYOBJECT()

Let's say you need to create a new empty object:

{
"data": {}
}

Creating:

{
"data": {{ NEWEMPTYOBJECT() }}
}

The result will be:

{
"data": {}
}

NEWEMPTYARRAY

This function allows you to create a new empty array.

Syntax

NEWEMPTYARRAY()

Let's say you need to create a new empty array:

{
"data": []
}

Creating:

{
"data": {{ NEWEMPTYARRAY() }}
}

The result will be:

{
"data": []
}

You can also read about these functions:

Did this answer your question?