使用 Apache NiFi 将 CSV 文件转换为 JSON [英] Convert a CSV file to JSON using Apache NiFi

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

问题描述

我正在尝试从本地文件系统读取 csv,并使用 Apache Nifi 将内容转换为 JSON 格式并将 JSON 格式文件放入本地系统.我已经成功转换了 csv 文件的第一行,但没有转换其他行.我错过了什么?

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?

输入:<代码>1,aaa,loc12,bbb,loc23,ccc,loc3

我的 nifi 工作流程如下:http://www.filedropper.com/mycsvtojson

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" }

推荐答案

有几种不同的方法可以做到这一点...

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

  • 一个自定义 Java 处理器,可读取 CSV 并转换为 JSON
  • 使用 ExecuteScript 处理器在 Groovy/Jython 脚本中执行类似的操作
  • 使用 SplitText 将原始 CSV 拆分为单行,然后使用您当前的方法与 ExtractText 和 ReplaceText,然后使用 MergeContent 重新合并在一起
  • 先使用 ConvertCsvToAvro,然后使用 ConvertAvroToJson

虽然最后一个选项会额外转换为 Avro,但它可能是最简单的解决方案,几乎不需要任何工作.

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

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

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