Description:

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.

</b>Name</b> </b>Default Value</b> </b>Allowable Values</b> </b>Description</b>
</b>Destination</b> 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.
</b>Return Type</b> 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'.
</b>Path Not Found Behavior</b> 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.
</b>Null Value Representation</b> 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.

</b>Name</b> </b>Value</b> </b>Description</b>
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:

</b>Name</b> </b>Description</b>
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.

Example:

How to work with flat JSON elements using EvaluateJsonPath processor?

Sample Input:

{              
  “Key1”:”value1”,
  “Key2”:”value2”,
  “Key3”:”value3”
}

Create custom properties as below to get values of the “Key1”, “Key2”, ”Key3”

Processor configuration of EvaluateJsonPath

Output of EvaluateJsonPath flowfile:
Processor output of EvaluateJsonPath

You can use these attributes using expression language(${Key1}, ${Key2}, ${Key3}) in the next processors.

Similarly we can work with nested JSON elements using below configuration in the processor.

Sample input:

{
	"json": {
		"nestedjson": {
			"Key1":"value1",
			"Key2":"value2",
			"Key3":"value3"
		}
	} 
}

Create custom properties as below to use values of the “Key1”, “Key2”, ”Key3” in the processor:
Processor configuration of EvaluateJsonPath

Similarly we can also work with array of values present inside JSON.

Sample input:

{
"json": [{       
		"Key1":"value1",
		"Key2":"value2",
		"Key3":"value3"        
	}]
}

Create custom properties as below to use values of the “Key1”, “Key2”, ”Key3” in the processor:
Processor configuration of EvaluateJsonPath

NOTE

The underlying JsonPath library loads the entirety of the streamed content into and performs result evaluations in memory. Accordingly, it is important to consider the anticipated profile of content being evaluated by this processor and the hardware supporting it especially when working against large JSON documents.