Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to convert json file to csv file using Apache Nifi?

avatar
Contributor

Hello,

I am trying to convert multiple json file into csv file in that,

In source folder i am getting different json file with different schema. need to convert json file to csv file with dynamic schema mapping and put that file into destination folder.

I have tried bellow flow,

1) getFile processor- to get file from source.

2) UpdateAttribute - set attribute schema.name : record

3) inferAvroSchema -configure Schema Output Destination : flowfile-attribute Input Content Type : json

4)convertRecord processor - Record Reader :JsonTreeReader Record Writer :CSVRecordSetWriter

5) putFile : put file into destination folder.

But in above flow getting error in convertRecord Processor,

Error: Failed to process StandardFlowFileRecord[uuid=69603ac0-ac43-44b5-82f3-5c1c89e4abaf,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1547526092906-1, container=default, section=1], offset=878, length=878],offset=0,name=orders1.json.avro,size=878]; will route to failure: Failed to create schema from the Schema Text after evaluating FlowFile Attributes.

Please find the attached screen-shot of configuration of convert record processor.

Thanks

96716-csvrecordsetwriter.png

96715-jsontreereader.png

96714-inferavroschema.png

5 REPLIES 5

avatar
Master Guru
@Mitthu Wagh

Make sure you are having ${inferred.avro.schema} attribute is associated with the flowfile.

I am not able to reproduce the error as i recreated same scenario on my end i have tried on NiFi-1.8.0 here is the template of my flow.

Upload the template to your instance and run, Let us know if you are having issue.json-to-csv-232797.xml

avatar
Contributor

Hi Shu,

I download the above template and imported into nifi-1.8.0.

when try to drag that template into nifi canvas it gives error.

Thanks in advance

96730-screenshot-from-2019-01-16-10-40-52.png

avatar
Master Guru
@Mitthu Wagh

Try to upload this template.

json-to-csv.xml

avatar
Contributor

Hey

still getting error, I am also using same nifi-1.8.0 version

96731-screenshot-from-2019-01-16-17-33-10.png

avatar
Contributor

if possible please share processor configuration sreen-shot