nojohnny101
nojohnny101

Reputation: 562

NIFI XML to JSON Null values

I am trying to run a very simple conversion flow that takes an input XML document and converts it to json using an Avro schema.

I must be doing something very wrong because I always get null values for even something simple like this:

<key1>value1</key1>

and the output is:

[{"key1":null}]

I followed this tutorial line by line here: https://pierrevillard.com/2018/06/28/nifi-1-7-xml-reader-writer-and-forkrecord-processor/

My AVRO Schema is defined as:

{
  "type" : "record",
  "name" : "MyClass",
  "namespace" : "com.test.avro",
  "fields" : [ {
    "name" : "key1",
    "type" : "string"
  } ]
}

What am I missing? The only difference I can see is that my xml has a slightly different structure than the example. in the example, the XML seems to have structure of:

<key1 value="value1"/>

But even trying to change my input to that results in the same null values.

I see other posts on this questions but no real solutions. Even the some of the comments on those threads about incorrect XML structure, I have changed to that and it is still not working. I'm sure it is something simple, any help would be appreciated.

I'm very new to NIFI, but really like the potential of the tool!

Upvotes: 1

Views: 425

Answers (1)

nojohnny101
nojohnny101

Reputation: 562

Turns out that the NIFI component ConvertRecord expects XML data to not be at the root level, and instead the defined to start at the 2nd level of the XML document.

So my defined AVRO Schema as correct, I just had to wrap my input XML data in a root tag, like this:

<root><key1>value1</key1></root>

Upvotes: 1

Related Questions