How to convert XML to JSON with new JSON structure in Nifi?

流过昼夜 提交于 2019-12-11 04:24:56

问题


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

For example, I have XML structure like this;

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

And result of JSON that I want.

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

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?


回答1:


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

  1. Convert the XML to JSON, this can be done with a ValidateRecord processor, you must define the schema of the json, so during this step you are going to check that the input data is ok.
  2. Modify the JSON structure using the JoltTransform processor.


来源:https://stackoverflow.com/questions/54842661/how-to-convert-xml-to-json-with-new-json-structure-in-nifi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!