Document toolboxDocument toolbox

JSON Parser

Description

This unit is a Processor unit type.

The JSON Parser unit parses events containing a properly formatted JSON, using Jackson.

An event comes in through the in port. The data field content is parsed using the Jackson JSON parser.

Successful input events are enriched with a new field containing the parse result, and the event is output through the out port.

If an error occurs, the input event is enriched with new fields describing the problem, and the event is sent through the error port.

Configuration

After dragging this unit into the Flow canvas, double-click it to access its configuration options. The following table describes the configuration options of this unit:

Tab

Field

Description

Tab

Field

Description

General

Name

Enter a name for the unit. It must start with a letter, and cannot contain spaces. Only letters, numbers, and underscores are allowed.

Description

Enter a description detailing the scope of the unit.

In field

Enter the name of the input event field containing JSON data.

Out field

Enter a name for the output event field containing the result.

Input ports

Port

Description

Port

Description

in

Events containing a properly formatted JSON to be parsed.

Output ports

Port

Description

Port

Description

out

Outputs events enriched with an extra field containing the parsed JSON.

error

Signals when an error occurred. Outputs input events enriched with standard error fields.

Example

In this example, we want use Flow to reformat a string to JSON format for further processing and transfer to a my.app data table.

First, we will use a Tick unit to send the fields when clicked.

In the Fields tab of the properties, add the string to be parsed

Enter the Type as string and in the Value field, the following JSON data:

{ "timestamp": 1234567890, "report": "Age Report", "results": [ { "name": "John", "age": 43, "city": "TownA" }, { "name": "Joe", "age": 10, "city": "TownB" } ] }

Then, we will link it to a JSON unit in order to format the string into JSON format. We need to tell the JSON unit which field in the Tick unit to source data from. In this case, the string field will be the in field. Enter a name for the out field for outgoing event data, in this case, data.

Next, a Map unit is used to extract the JSON results and remove other fields. In the Fields to add tab, insert the field to be extracted and the expression for the results.

In the Fields to remove tab, remove all other data, in this case, the data and string fields.

Link the out port of the JSON Parser unit to the in port of the Map.

Next, a Detacher unit will transform the list created by the Map unit into a sequence of events containing successive list items. In the properties, enter the field containing the list, in this case, the Results field previously set.

Link the out port of the Map unit to the in port of the Detacher.

Now, another Map unit is needed to extract each separate list item output by the Detacher as one event.

In the Fields to add tab, add the following fields:

In the Fields to remove tab, remove the Results field.

Finally, we will link its out output port to a Devo sink unit to send the formatted events to a my.app table.

Download this example

You can try this flow by downloading this JSON and uploading it to your domain using the Import option:

Â