如何在 Nifi 中使用新的 JSON 结构将 XML 转换为 JSON? [英] How to convert XML to JSON with new JSON structure in Nifi?

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

问题描述

我从 Web 服务获得了不同的 XML.我想将此 XML 转换为 JSON,但必须更改结构.

I get different XMLs from web services. I want to convert this XML to JSON, but structure must be changed.

例如,我有这样的 XML 结构;

For example, I have XML structure like this;

<root>
    <A attr="attr1">VAL</A>
    <B attr="attr2">VAL</B>
</root>

以及我想要的 JSON 的结果.

And result of JSON that I want.

{
   "root":{
      "Items":[
         {
            "tag_name":"A",
            "attr":"attr1",
            "value":"VAL"
         },
         {
            "tag_name":"B",
            "attr":"attr2",
            "value":"VAL"
         }
      ]
   }
}

我怎样才能在 Nifi 中做到这一点?ConvertRecord 还是 UpdateRecord?另外,如果可以使用基于记录的处理器,应该如何为此读写模式?

How can I do this in Nifi? ConvertRecord or UpdateRecord? Also, how should read and write schema for this if record based processors may be used?

推荐答案

你可以用纯 NiFi 流程来做,步骤是:

You can do it with a pure NiFi flow, the steps to do this are:

  1. 将 XML 转换为 JSON,这可以使用 ValidateRecord 处理器完成,您必须定义 json 的架构,因此在此步骤中,您将检查输入数据是否正常.
  2. 使用 JoltTransform 处理器修改 JSON 结构.

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

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