Support Questions
Find answers, ask questions, and share your expertise

NiFi, Attribute to csv

Explorer

hi all,

I have flow content is json [{"a":"IboECKV", "b":"2018-09-14 21:05:02.000Z", "c":"2132a4"}, {"a":"IboECKV_a2", "b":"2018-09-14 21:05:02.000Z", "c":"2132a4_c2"}]

is it possible to convert it to csv using Attribute to csv without name each key in json (because it is dynamic array json)?


can we use regular expression as $1, $.* or ...??

Many thanks

91572-attributestocsv.png

4 REPLIES 4

Super Guru
@Thuy Le

Attributes to CSV processor works on attributes associated with the flowfile.

We first need to extract the attributes from the content of the flowfile then use AttributeToCSV processor to create an csv file based on the attributes list.

As you have mentioned in the question you are having dynamic array json it will be hard to extract the values of the json keys and create csv file dynamically.

Refer to this link for more details regards to AttributeToJSON processor and the usage/configuration of AttributesToCSV processor also the same.

-

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.

Explorer

Hi @Shu,

Thank you so much for your answers, however, the example is too manually, I have to specify all needed attributes/keys.

Super Guru
@Thuy Le

Another way is to write a script to extract all the values and keep them as attributes to the flowfile.

Then use UpdateAttribute processor to delete all the

Delete Attributes Expression

<not_required_attrbutes>.*|<not_required_attrbutes>.*

Then use AttributesToCSV processor with Regex

Attributes Regular Expression

.*

Destination

flowfile-content

Refer to this link for more details regards to extraction of attributes dynamically from the json data.

**keep in mind if we add significant number of attributes dynamically to the flow file, As attributes are hold in memory this will cause performance issues.

Explorer

Hi @Shu,

Nice to hear from you, That is great idea, however, .* is not work in AttributeToCSV

Do you have any ideas to solved that issue?

Many thanks

; ;