1

I am trying to read a csv from local file system and convert the content into JSON format using Apache Nifi and put the JSON format file in the local system. I have succeeded in converting the first row of csv file but not other rows. What am I missing?

Input: 1,aaa,loc1 2,bbb,loc2 3,ccc,loc3

and my nifi workflow is as here: http://www.filedropper.com/mycsvtojson

My output is as below which is desired format but I want that to happen for all the rows.

{ "id" : "1", "name" : "aaa", "location" : "loc1" }

2 Answers 2

7

There are a few different ways this could be done...

  • A custom Java processor that reads in a CSV and converts to JSON
  • Using the ExecuteScript processor to do something similar in a Groovy/Jython script
  • Use SplitText to split your original CSV into single lines, then use your current approach with ExtractText and ReplaceText, and then a MergeContent to merge back together
  • Use ConvertCsvToAvro and then ConvertAvroToJson

Although the last option makes an extra conversion to Avro, it might be the easiest solution requiring almost no work.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried using SplitText and it worked... and yes using ConvertCsvToAvro is more convenient.
2

This question is a bit older, but there is now a ConvertRecord processor in NiFi 1.3 and newer, which should be able to handle this conversion directly for you, and it avoids having to use split up the data by creating a single JSON array with all of the values, if that is desirable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.