nifi-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aldrin Piri <>
Subject Re: How to extract scalar info of json array using EvaluateJsonPath processor?
Date Fri, 13 May 2016 01:36:54 GMT
Hi Keith,

I threw together a quick example of how this is done and made it available
as a GitHub Gist [1].  In that template, the core logic of transforming the
evaluated JsonPath expression result is in the "Count IDs as Attribute"
processor which is making use of the  'Advanced' menu for UpdateAttribute.
As a caveat, this is quite quick and dirty, but illustrates how you can
extract values from content to attributes for your case.

One thing I would like to highlight is that Expression Language (EL) is
exclusively against FlowFile attributes.  The pattern that typically
happens is an extraction/selection of key features/characteristics from the
content, promoted as attributes for further manipulation and handling.
This approach is taken in the referenced template.

I additionally noticed that I was also incorrect in my previous statement
and overlooked the length() operator for the JsonPath library [2].  This,
however, does not seem to apply to expressions for EvaluateJsonPath and
will likely need some additional inspection.  I have created an issue for
that [3].

Please let us know if you have any additional questions!



On Thu, May 12, 2016 at 2:52 PM, Keith Lim <> wrote:

> Hi Aldrin,
> I am still not able to get this to work.  I see that the expression
> language guide (
> mentions how to work with flowfile attributes, but not on the flowfile
> content itself.  What is the builtin variable that points to the flowfile
> content that I can used with the expression language?
> For illustration, let's say I have the below json as the content of a
> flowfile.  What processor can I used to take this flowfile as input and how
> can I extract the count of item in the json array "results" below.  I want
> to assign it to a user defined attribute in the processor.
> { "results" :  [   {  "name" : "Jane Doe",  "id" : "1" },   {  "name" :
> "John Doe", "id" : "2" }  ] }
> Thanks for all your help.
> Thanks,
> keith
> ------------------------------
> *From:* Aldrin Piri <>
> *Sent:* Thursday, May 12, 2016 1:32 PM
> *To:*
> *Subject:* Re: How to extract scalar info of json array using
> EvaluateJsonPath processor?
> Hi Keith,
> Scanning over some of the docs, it does not appear that JsonPath supports
> a count operator but could possibly be used to extract from your source
> document that could possibly be manipulated using something like
> allDelinatedValues [1].  Certainly not the most elegant approach, but could
> work.
> If you would like some additional help, a sample to work from would be
> nice to give some more concrete assistance.
> [1]
> On Thu, May 12, 2016 at 11:52 AM, Keith Lim <> wrote:
>> I have a flow file with json array and would like to use EvaluateJsonPath
>> processor the extract the item count of that array.  Does the Nifi
>> Expression Language in combination of json path feature supports this without
>> writing script?  What is the syntax?
>> Thanks,
>> Keith

View raw message