0
votes

I have a requirement where I am converting data from an API to JSON format. The output of the API is initially in XML, so I am using XMLReader controller service to read the XML data, and JSONRecordSetWriter controller service to convert it to JSON format in Apache Nifi 1.9.2.

When I use ConvertRecord processor with the same controller services, my output merely shows the avro schema and not the data expected. I have tried out many options like using AvroSchemaRegistry controller service, but only the schema is seen and null values are passed. Can anyone explain this behavior?

XML flowfile output:

<field1 value="AAAA"/>
   <field2 value="BBBB"/>
   <field3 value="male"/>

JSON output:

[ {
  "field1" : null,
  "field2" : null,
  "field3" : null
} ]
1

1 Answers

0
votes

The documentation specifies that "Records are expected in the second level of XML data, embedded in an enclosing root tag." Your input file appears to be a list of XML tags with no root tag enclosing them.

You could use ReplaceText to wrap the XML in a root tag, then the XMLReader should parse the fields as expected.