[ 
https://issues.apache.org/jira/browse/NIFI-10396?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17634547#comment-17634547
 ] 

Matt Burgess commented on NIFI-10396:
-------------------------------------

Coming back to this; I think I was too attached to the processors that may 
leverage this, where this is an EL function. It's been a while but I think my 
issue was more with having an EL exception in various processors. I would think 
an isJson() or validateJson() or even validateFormat("json") would help in the 
EL case. To me the behavior in question is that is jsonPath() is called with 
invalid JSON there should be an error vs an empty string. That may cause 
undesirable behavior in processors like UpdateAttribute which don't have a 
failure relationship. If NIFI-10612 makes this case Overcome By Events (OBE), 
happy to resolve/close it. 

> Expression Language jsonPath throws error instead of returning empty string 
> when subject is invalid JSON
> --------------------------------------------------------------------------------------------------------
>
>                 Key: NIFI-10396
>                 URL: https://issues.apache.org/jira/browse/NIFI-10396
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Core Framework
>    Affects Versions: 1.17.0
>            Reporter: Daniel Stieglitz
>            Assignee: Daniel Stieglitz
>            Priority: Major
>         Attachments: 
> 0001-NIFI-10396-Refactored-code-to-have-jsonPath-jsonPath.patch, 
> JsonPathInvalidJsonYieldsFlowFiles.xml
>
>
> Per the [Expression Language 
> documentation|https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#jsonpath]
>  for jsonPath "An empty string is generated if the Subject does not contain 
> valid JSON, the _jsonPath_ is invalid, or the path does not exist in the 
> Subject." Further in the documentation it states "An empty subject value or a 
> subject value with an invalid JSON document results in an exception 
> bulletin." This would seem to indicate with invalid JSON an empty string is 
> returned and the processor which is handling the Expression Language will get 
> an empty string and not have to yield any flow files. Attached is a template 
> which indicates that instead of a returned empty string, an exception is 
> thrown and the processor is yielding flow files causing its queue to backup.
> The attached template [^JsonPathInvalidJsonYieldsFlowFiles.xml] 
> uses a RouteOnAttributeProcessor to determine whether an attribute value is 
> valid JSON or not. Two Expression Language expressions are used both of which 
> use JsonPath of $ (which should return the whole JSON document) chained with 
> isEmpty():not() or isEmpty() to determine if the attribute value is valid 
> JSON or not.
> Note how the flow file with a valid JSON attribute is routed correctly while 
> the flow file with invalid JSON is yielded and not routed correctly. Instead 
> of routing to the invalid relationship the flow files are backing up in the 
> queue.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to