JSON Transformer enables transformations in the JSON being processed in your pipeline.

By using a configuration form, it's possible to make a lot of actions.

Take a look at the configuration parameters of the component:

  • Actions: it's possible to add many actions such as Rename property, Edit property, Remove property and Remove property with Condition. See more details below:

- Rename Property: renames the JSON key to a new key that can be composed by a static or dynamic value composed by Double Braces.

- Edit Property: allows the transformation of the values in a property through Double Braces.

- Remove Property: removes properties in any structure of JSON.

- Remove Property With Condition: by using the logical operators of the functions, it's possible to define a condition so that "true" is returned indicating when the property must be removed.

  • Action Settings

- Root path: must be activated when the JSON property is in the root of the object.

- Path (Dot notation): must be filled when the JSON property isn't in the root of the object. It allows to indicate dot notation, which makes it simple to access different JSON levels, including going through the JSON array and object.

  • Key Values: must be filled with the key you want to transform (it will be shown according to the chosen type of Action).

When using Double Braces, the values of the properties to be changed must be accessed with the use of the word "item". With the word "item" it's possible to obtain values of all properties in the same JSON level that's being accessed.

Examples:

{{ item.keyName }} 

{{ CONCAT(item.customer.id, item.customer.name) }} 

{{ FORMATDATE( item.orders.dateAdded, "dd-MM-yyyy", "dd MMM yyyy") }}

  • Props to Remove: must be filled with 1 or more keys that you want to remove (it will be shown according to the chosen type of Action).
  • Fail On Error: if the option is activated, the execution of the pipeline with error will be interrupted; otherwise, the pipeline execution continues and the result will be the input JSON and the "_error" attributes put under the attribute that was being transformed.

Messages flow

Input

This component doesn't expect any specific input message, only if an expression in Double Braces is informed in some of its fields.

Output

Because it's a component that transforms the input JSON, the output is the result of the configurations defined by you.

If no property defined in the component configurations is found in JSON, the result will be the same one of the input JSON.

To better understand the messages flow in the Platform, click here and read our article.

JSON Transformer in Action

See below how the component behaves in certain situations and what its respective configurations are.

  • Renaming properties

The properties can be renamed through static or dynamic values composed by Double Braces. These properties can be in an object, array or in the root.

In this example, see how to rename "a" to "id" and "b" to "name". The component configurations must be:

Input

{
"products": [
{
"a": 1,
"b": "Table"
},
{
"a": 2,
"b": "Chair"
}
]
}

Configurations

Output

{
"products": [
{
"id": 1,
"name": "Table"
},
{
"id": 2,
"name": "Chair"
}
]
}

  • Editing properties

The values can be transformed by applying Double Braces and functions from the Digibee Platform. This property can be in an object, array or in the root.

It's possible to apply functions such as FORMATDATE, CONCAT, REPLACE, FORMATNUMBER, among others.

To better understand how these resources work, read our article by clicking here.

In this example, see how to transform the "id" from Number to String. The component configurations must be:

Input

{
"products": [
{
"id": 1,
"name": "Table"
},
{
"id": 2,
"name": "Chair"
}
]
}

Configurations

Output

{
"products": [
{
"id": "1",
"name": "Table"
},
{
"id": "2",
"name": "Chair"
}
]
}

  • Removing properties with decision conditions

The properties can be removed by using the logical operators of the Double Braces functions. It's possible to define a condition that, when resolved to "true", will indicate that the property must be removed. These properties can be in an object, array or in the root.

In this example, see how to remove "description" with a null value. The component configurations must be:

Input

{
"products": [
{
"id": 1,
"name": "Table",
"description": "Tea Table",
},
{
"id": 2,
"name": "Chair",
"description": null
}
]
}

Configurations

Output

{
"products": [
{
"id": 1,
"name": "Table",
"description": "Tea Table",
},
{
"id": 2,
"name": "Chair"
}
]
}

  • Removing properties only by the name

The properties can be removed just by declaring their names in the “Properties to be removed” field. These properties can be in an object, array or in the root.

Additional Information

Some of the parameters above accept Double Braces. To better understand how this language works, read our article by clicking here.

Did this answer your question?