问题描述
我正在尝试从本地文件系统读取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
Input: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" }
{ "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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!