Description and usage of JoltTransformJSON:

Applies a list of Jolt specifications to the flowfile JSON payload. A new FlowFile is created with transformed content and is routed to the ‘success’ relationship. If the JSON transform fails,the original FlowFile is routed to the ‘failure’ relationship.

Tags:

JSON, jolt, transform, shiftr, chainr, defaultr, removr, cardinality, sort

Properties:

In the list below, the names of required properties appear in bold. Any other properties (not in bold) are considered optional. The table also indicates any default values, and whether a property supports the Expression Language Guide..

Name Default Value Allowable Values Description
Jolt Transformation DSL jolt-transform-chain *ardinality
* Chain
* Default
* Modify-Default
* Modify-Define
* Modify-Overwrite
* Remove
* Shift
* Sort
* Custom
Specifies the Jolt Transformation that should be used with the provided specification.
Custom Transformation Class Name Fully Qualified Class Name for Custom Transformation
Custom Module Directory Comma-separated list of paths to files and/or directories which contain modules containing custom transformations (that are not included on NiFi's classpath)
Jolt Specification Jolt Specification for transform of JSON data. This value is ignored if the Jolt Sort Transformation is selected.
Supports Expression Language: true

Relationships:

Name Description
success The FlowFile with transformed content will be routed to this relationship
failure If a FlowFile fails processing for any reason (for example, the FlowFile is not valid JSON), it will be routed to this relationship

Reads Attributes:

None specified.

Writes Attributes:

Name Description
mime.type Always set to application/json

State management:

This component does not store state.

Restricted:

This component is not restricted.

Summary:

The Jolt utilities processing JSON are not not stream based therefore large JSON document transformation may consume large amounts of memory. Currently UTF-8 FlowFile content and Jolt specifications are supported. A specification can be defined using Expression Language where attributes can be referred either on the left or right hand side within the specification syntax. Custom Jolt Transformations (that implement the Transform interface) are supported. Modules containing custom libraries which do not existing on the current class path can be included via the custom module directory property. Note: When configuring a processor if user selects of the Default transformation yet provides a Chain specification the system does not alert that the specification is invalid and and will produce failed flow files. This is a known issue identified within the Jolt library.

How to configure?

This sample explains how to configure the JoltTransformJSON processor and perform the various transformations on the given input JSON file.

Overall workflow:

JoltTransformJsonConfig

Steps Involved:

Step 1: Create a JSON file as shown in the following image.

JoltTransformJsonConfig

Step 2: Drag and drop the GetFile processor to read the input JSON file content as shown in the following image.

JoltTransformJsonConfig

Step 3: Drag and drop the UpdateAttribute processor for specifying the spec JSON content required for the Jolt transformations.

JoltTransformJsonConfig

The operations such as shift, remove, sort, cardinality, remove, modify, and even custom transformations can also be performed on the input JSON data.

Step 4: Drag and drop the JoltTransformJSON processor into the canvas and mention the spec attribute on the Jolt Specification property.

JoltTransformJsonConfig

Step 5: Drag and drop the PutFile processor into the canvas to save the transformed JSON data.

JoltTransformJsonConfig

The result of the shift operation from the location to counterTop is shown in the following image.

JoltTransformJsonConfig