问题
I get different XML
s 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:
- 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.
- 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