Created on 09-27-2018 06:01 PM - edited 08-17-2019 10:05 PM
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
Created 09-28-2018 01:55 AM
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.
Created 09-30-2018 04:27 PM
Hi @Shu,
Thank you so much for your answers, however, the example is too manually, I have to specify all needed attributes/keys.
Created 09-30-2018 10:12 PM
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.
Created 10-02-2018 07:52 AM
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