Support Questions

Find answers, ask questions, and share your expertise

convert json to colume based text in NIFI

avatar
New Contributor

Hi I am looking to convert a json file in Nifi and have been playing around with a few processors like convert record.

The below is json I am receiving -

 

{
  "report" : "file1.CSV",
  "Report Date" : "2022-02-09 13.24.58",
  "reject" : "0",
  "total" : "7",
  "processed" : "7"
}

 

 

And needs to be converted to a text file in columnar/dictionary format though and should look like this -

 

"report" | "file1.CSV"|
"Report Date" | "2022-02-09 13.24.58"|
"reject" | "0"|
"total" | "7"|
"processed" | "7"

 

Its quite straight forward to just replace the "," with "|" and remove the "{}" but I was wondering is there a way to write to a column based text file?

1 REPLY 1

avatar
Super Guru

Use a ConvertRecord processor with a JsonTreeReader as the record reader and a CSVRecordSetWriter as the record writer.

 

Configure the CSVRecordSetWriter with the following:

araujo_0-1644465429656.png

 

HTH,

André

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.