Description and usage of EvaluateJsonPath:

Evaluates one or more JsonPath expressions against content of a FlowFile. Expressions are assigned to Attributes or written to content of the FlowFile.

Tags:

JSON, evaluate, JsonPath

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.

Name

Default Value

Allowable Values

Description

Destination flowfile-content * flowfile-content
* flowfile-attribute
Indicates whether the results of the JsonPath evaluation are written to the FlowFile content or a FlowFile attribute; if using attribute, must specify the Attribute Name property. If set to flowfile-content, only one JsonPath may be specified, and the property name is ignored.
Return Type auto-detect * auto-detect
* JSON
* scalar
Indicates the desired return type of the JSON Path expressions. Selecting 'auto-detect' will set the return type to 'json' for a Destination of 'flowfile-content', and 'scalar' for a Destination of 'flowfile-attribute'.
Path Not Found Behavior ignore * warn
* ignore
Indicates how to handle missing JSON path expressions when destination is set to 'flowfile-attribute'. Selecting 'warn' will generate a warning when a JSON path expression is not found.
Null Value Representation empty string * the string 'null'
* empty string
Indicates the desired representation of JSON Path expressions resulting in a null value.

Dynamic Properties:

Dynamic Properties allow the user to specify both the name and value of a property.

Name

Value

Description

A FlowFile attribute(if <Destination> is set to 'flowfile-attribute') A JsonPath expression If <Destination>='flowfile-attribute' then that FlowFile attribute will be set to any JSON objects that match the JsonPath. If <Destination>='flowfile-content' then the FlowFile content will be updated to any JSON objects that match the JsonPath.

Relationships:

Name

Description

matched FlowFiles are routed to this relationship when the JsonPath is successfully evaluated and the FlowFile is modified as a result
unmatched FlowFiles are routed to this relationship when the JsonPath does not match the content of the FlowFile and the Destination is set to flowfile-content
failure FlowFiles are routed to this relationship when the JsonPath cannot be evaluated against the content of the FlowFile; for instance, if the FlowFile is not valid JSON

Reads Attributes:

None specified.

Writes Attributes:

None specified.

How to configure?

Step 1:Drag and drop the EvaluateJsonPath processor to canvas.

Step 2: Double click the processor to configure, the configuration dialog will be opened as follows,

Processor configuration of EvaluateJsonPath

Step 3: Check usage of each property and update those values.

Properties and usage:

Destination: Specifies whether the result of the jsonpath expression should be written as attribute or content.

Return Type: Specifies the return type of the jsonpath expression.

Path Not Found Behavior: Specifies how to handle if given jsonpath expression is not found when destination is set to flow file attribute. Either ignore or send as warning.

Null Value Representation: Specifies how to indicate null representation of given json path expression.

Writing JSON path expression:

Sample Input:

{

"syncfusion":{

  "software":"DIP",
  "employee":{

    "name":"admin",
    "id":"3710"
      
	    }
   
    }

}

In this example, the root node is Syncfusion, and the child nodes are type and data. The employee’s name is found in the child element, name of the node, and data.

Thus, the JSON path expression to extract the employee’s name is:

In dot-notation:

”$.syncfusion.employee.name”

In bracket-notation:

”$[‘syncfusion’] [‘employee’] [‘name’]”

The response returns a string that contains the employee’s name.

Output: admin.

Destination as flow file content:

If we set the Destination to flow file-content in the EvaluateJsonPath processor, we can have only one JSON Path expression, and the property name is ignored.

The configuration of the EvaluateJsonPath processor’s destination as flow file content to create a custom property to get the root node as output is shown below:

Destination as flow file content configuration

Destination as Flow file Attribute:

If we set the Destination to flow file-attribute, each JSON Path will be extracted to the named attribute value.

The configuration of the EvaluateJsonPath processor’s destination as flow file attributes to get each path as attribute values is shown below:

Destination as Flow file Attribute configuration

Sample Workflow:

This sample workflow uses the EvaluateJsonPath processor to evaluate one or more JSON Path expressions against the content of a flow file in the Data Integration platform.

List of processors used in this sample:

Processor

Comments

GenerateFlowFile Gives incremental SQL statements based on partition size.
EvaluateJsonPath Executes all the SQL statements that got generated by GenerateTableFetch processor. In Data Integration Platform every ExecuteSQL processor results default format is Avro.
PutFile Converts all the Avro data to JSON data.


Workflow screenshot

Overall workflow

Step 1: Configure GenerateFlowFile processor:

Drag and drop the GenerateFlowFile processor to the canvas area. The GenerateFlowFile processor, which is used reads the content from the given text, generates flow files, and acts as an upstream connection.

Configure the property Custom text as sample input needed to generate as flow file and other required properties in configuration dialog as shown in the following screenshot.

Configuration of GenerateFlowFile processor

Configuration of custom text

Step 2: Configure EvaluateJsonPath processor:

Drag and drop the EvaluateJsonPath processor to the canvas area, and the EvaluateJsonPath processor evaluates one or more JSON path expressions against the content of a flow file. Configure the required properties in the configuration dialog, as shown in the following screenshot. Also, make a connection between the GenerateFlowFile and EvaluateJsonPath with a ‘Success’ relationship.

Flow-File content configuration:

Flow file content configuration

Flow-file Attribute configuration:

Flowfile attribute configuration

Step 3: Configure the PutFile processor

Drag and drop the PutFile processor to the canvas area, and the PutFile processor which is used writes the evaluated Flow Files to the local file system and acts as a downstream connection. Configure the required properties in the configuration dialog, as shown in the following screenshot. Also, make the connection between the EvaluateJsonPath and PutFile with a ‘Matched’ relationship.

Putfile processor configuartion

Step 4: Starting a workflow

Once all processors are configured, start the workflow. You can see the Data flow through the processor.

Starting workflow

Output Data:

Flow-file content output:

You can get the evaluated JSON output in your local file system when flow-file content as the destination.

Flow file content output

Flow-file Attributes values:

You can get attribute values in the flow-file when viewing attribute as a destination. If you need the results in the content of the Flow File, use a Replace Text processor afterward to collect the attribute values into the content.

Flow file attribute output