首页 > 解决方案 > How to convert CSV to JSON using Apache Nifi?

问题描述

How to convert CSV to JSON using Apache Nifi?
I have a CSV file and I need to covert to json. How to draw a normal flow diagram. Please tell me the properties and figure details. My understanding is 4 block has to there. 1.GenerateFLow 2.ConverttoAvro 3.Converttojson 4.Savethefile. I am new to the Nifi and I have installed nifi, struggling to configure

"model","speed","mileage"
"audi",4,2
"benz",4,10
"bmw",7,4
"jaguar",7,22

My Json

[
  {
    "model": "audi",
    "speed": 4,
    "mileage": 2
  },
  {
    "model": "benz",
    "speed": 4,
    "mileage": 10
  },
  {
    "model": "bmw",
    "speed": 7,
    "mileage": 4
  },
  {
    "model": "jaguar",
    "speed": 7,
    "mileage": 22
  }
]

I went through Convert a CSV file to JSON using Apache NiFi

标签: apache-nifi

解决方案


您所描述的方法是.old (needs to follow if you are using prior to NiFi-1.2 version)

NiFi-1.2开始引入record oriented processors

  • 对于您的情况,使用ConvertRecord处理器并配置/启用记录读取器(CSVReader)/写入器(JsonSetWriter)控制器服务。

  • 然后 NiFi ConvertRecord处理器读取传入的CSV数据并以JSON格式写入输出流文件。

请参阅convertCsvtoJson链接描述如何使用 ConvertRecord 处理器的分步过程。

Starting from NiFi-1.2 Version 流动:

1.GenerateFlowFile 
2.ConvertRecord
3.SaveFile (Using PutFile/PutHDFS)

Prior to NiFi-1.2 Version 流动:

1.GenerateFlowFile
2.InferAvroSchema
3.ConvertCSVToAvro
4.ConvertAvroToJSON

推荐阅读