Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

Apache Nifi - Adding attributes as newlines FlowFilw content

avatar
Expert Contributor

Hi,

I have a scenario where My GetHTTP processor gets a JSON of system health metrics. I extract the attributes from the Json to essentially extract the desired metrics that I want to display on a Graph.

Input: Suppose following attributes I extracted from Json using EvaluateJSONPath processor:

metric1='<myconmapy>.<metric1> <value> <timestamp>'

metric2='<myconmapy>.<metric2> <value> <timestamp>'

metric3='<myconmapy>.<metric3> <value> <timestamp>'

Output: I want to convert all the above mentioned attributes/metrics as lines of FlowFile content, such that one FlowFile content will look like following (each line contains an attribute value):

<myconmapy>.<metric1> <value> <timestamp>

<myconmapy>.<metric2> <value> <timestamp>

<myconmapy>.<metric3> <value> <timestamp>

Is there a way to achieve the above mentioned Output using Nifi processors?

Thanks

1 ACCEPTED SOLUTION

avatar

Yes, use a ReplaceText processor and NiFi's Expression Language syntax to reference your attributes and construct the content line. Tip: switch the evaluation mode for ReplaceText to 'Always Replace' as an optimization for your use case.

https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.ReplaceText/in...

https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html

View solution in original post

6 REPLIES 6

avatar

Yes, use a ReplaceText processor and NiFi's Expression Language syntax to reference your attributes and construct the content line. Tip: switch the evaluation mode for ReplaceText to 'Always Replace' as an optimization for your use case.

https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.ReplaceText/in...

https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html

avatar
Expert Contributor

Awesome, I solved it by using the append('\n') for attribute:

${m1:append('\n')}${m2:append('\n')}${m3}

Thanks a lot,

avatar
Rising Star

yeah thanks.. append works.. \\n (double backslash) doesnt.. I was doing this while writing count to file.. it now works.. The count is: ${executesql.row.count:append('\n')}

avatar

When entering text values into NiFi you should be able to hit "Shift-Enter" and it will give you true new lines. See attached screenshot

6264-screen-shot-2016-08-02-at-112410-am.png

avatar
New Member

Joe - What processor is being illustrated?

avatar
Master Mentor
@Obaid Salikeen

Try using \\n (double backslash) or using 'Shift + enter" in the expression language editor box to create new lines in your replacement string as shown by Joe Witt above. Thanks,

Matt