NiFi使用ConvertRecord将json转换为csv [英] NiFi convert json to csv using ConvertRecord

查看:980
本文介绍了NiFi使用ConvertRecord将json转换为csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在apache nifi中有一个json流,其中包含动态字段(最多11个字段),我想将其转换为csv文件.

i have a stream of json in apache nifi that contain dynamic fields (maximum 11 fields) and i want to convert it to csv file.

样本json:

{  
   "field1":"some text",
   "field2":"some text",
   "field3":"some text",
   "field4":"some text",
   "field5":"some text",
   "field6":"some text",
   "field7":"some text"
}

我不想使用replace或json评估;我如何使用ConvertRecord? 使用这个处理器是如此奇怪且难以工作...

i don't wanna using replace or json evaluate; how i do it with ConvertRecord? using this processor is so odd and hard to work...

清除有关动态字段的表达式: 我总共有11个字段.一条记录可能包含7个字段,下一条记录可能包含11个字段,接下来的9个字段...

Clear expression about dynamic fields: i have 11 fields at total. one record may have contain 7 fields, and next record may contain 11 fields and next 9 fields...

推荐答案

下面提供的步骤将帮助您完成此操作.

The steps provided below will help you in getting this done.:

  • 将生成/输出JSON文件的源处理器连接到ConvertRecord.
  • 配置ConvertRecord并将记录读取器"设置为使用JsonTreeReader控制器服务,并且将记录写入器"设置为使用CSVRecordSetWriter控制器服务
  • 配置两个控制器服务,并将Schema Registry属性设置为使用AvroSchemaRegistry
  • 配置AvroSchemaRegistry.转到属性"标签,然后单击 + 按钮,该按钮可用于添加动态属性.
  • 提供一些属性名称(例如:mySchema),并为该值提供输入JSON所需的Avro模式. (您可以使用InferAvroSchema处理器为JSON生成Avro模式)
  • 同时配置JsonTreeReaderCsvRecordSetWriter并将模式名称"属性设置为上面提供的名称,在本例中为mySchema.
  • 根据需要将ConvertRecord的关系连接到下游处理器.
  • Connect your source processor which generates/outputs the JSON files to ConvertRecord.
  • Configure ConvertRecord and set 'Record Reader' to use JsonTreeReader controller service and 'Record Writer' to use CSVRecordSetWriter controller service
  • Configure both the controller services and set Schema Registry property to use AvroSchemaRegistry
  • Configure AvroSchemaRegistry. Go to 'Properties' tab and click the + button which lets you add a dynamic property.
  • Give some property name (ex: mySchema) and for the value, give the Avro schema expected for your input JSON. (You can use InferAvroSchema processor to generate Avro schema for your JSON)
  • Configure both JsonTreeReader and CsvRecordSetWriter and set the 'Schema Name' property to the name provided above, in this case, mySchema.
  • Connect the relationships of ConvertRecord to downstream processors according to your need.

这篇关于NiFi使用ConvertRecord将json转换为csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆