在Nifi中将JSON转换为CSV [英] Convert JSON to CSV in nifi

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

问题描述

我想在nifi中将JSON文件转换为CSV.我们可以使用Python和其他编程语言来实现这一目标,并且上面有多篇文章.我有多个JSON文件,每个文件都有不同的架构(一个特定的文件将只有一个架构).我可以看到有一些模板可以将CSV转换为JSON和其他转换.但是我没有看到任何将JSON数据转换为CSV的模板.我浏览了文章 https: //community.hortonworks.com/articles/64069/converting-a-large-json-file-into-csv.html ,但是在这里我们很难对模式进行编码.由于我有多个文件,并且每个文件都有不同的架构,因此无法对架构进行硬编码.有什么建议请.

I want to convert JSON files to CSV in nifi. We can achieve this in Python and other programming languages and have multiple articles on it. I have multiple JSON files and each file has different schema(one specific file will have one schema only). I can see there are templates to convert CSV to JSON and other conversions. But I didn't see any template to convert JSON data to CSV. I have gone through the article https://community.hortonworks.com/articles/64069/converting-a-large-json-file-into-csv.html ,however here we are hard coding the schema. As I have multiple files and each file has different schema, I can't hardcode the schema. Any suggestions please.

推荐答案

格式之间的转换通常是通过ConvertRecord通过插入适当的记录读取器和记录写入器(在本例中为JSON读取器和CSV写入器)来完成的.

Conversion between formats is typically done through ConvertRecord by plugging in the appropriate record reader and record writer, in this case a JSON reader and CSV writer.

要使用记录处理器,您需要为数据定义Avro模式并将其放入模式注册表中,NiFi提供了本地模式.

To make use of the record processors you need to defined Avro schemas for your data and put them in a schema registry, NiFi provides a local one.

有很多示例,并在其中发布了有关记录的东西,此幻灯片展示了一个CSV到JSON的示例,但是很容易扭转这种情况:

There are lots of examples and posts out there about the record stuff, this slide deck shows an example of CSV to JSON, but would be easy to reverse the situation for your scenario:

https://www.slideshare.net/BryanBende/apache-nifi -记录处理

此信息还有其他一些信息: https://bryanbende.com/development/2017/06/20/apache-nifi-records-andschema-registries

This post has some other info: https://bryanbende.com/development/2017/06/20/apache-nifi-records-and-schema-registries

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

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