nifi-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Bende <bbe...@gmail.com>
Subject Re: Which processor to use to cleanly convert xml to json?
Date Wed, 01 Jun 2016 16:16:31 GMT
Hi Keith,

There is currently no built in processor that directly transforms XML to
JSON.

TransformXML leverages XSLT to transform and XML document into some other
format.
In that post, the XSLT happens to transform into JSON, but it looks like
maybe it only handles top-level elements and not nesting.

I would say your options would be to modify that stylesheet to support
nested elements, or if you have a specific well-defined XML format you
could write a custom processor that is specific to your format.
For a custom processor your possibly generate JAXB objects from your XML
schema, unmarshall the XML into those objects, then remarshall them as JSON.

Others may have additional suggestions of something that could be done
through ExecuteScript.

-Bryan


On Wed, Jun 1, 2016 at 12:10 PM, Keith Lim <Keith.Lim@ds-iq.com> wrote:

> Any help guidance much appreciated.
>
> Thanks,
> Keith
> ------------------------------
> From: Keith Lim <Keith.Lim@ds-iq.com>
> Sent: ‎5/‎31/‎2016 4:07 PM
> To: users@nifi.apache.org
> Subject: Which processor to use to cleanly convert xml to json?
>
> Which processor should I use to cleanly convert from xml to json?
>
> This article illustrates using TransformXML with a stylesheet to convert
> xml to json.
>
>
> https://community.hortonworks.com/articles/29474/nifi-converting-xml-to-json.html
>
> However, I am seeing that it does not convert values with special tag such
> the embedded <br> tag as below:
>
>
> XML fragment:
>
> <record>
>
>     <property1>Lake<BR/>River<BR/>National_State Park</property1>
>
> <property2>A:Value1<BR/>B:Value2<BR/>C:Value3<BR/>D:Value4<BR/>E:Value5</property2>
>
> </record>
>
>
> Converted Json:
>
>
> { "record" : {
>
>         "property1" : { "BR" :["",""] },
>         "property2" : { "BR" :["","","",""] }
>
> }}
>
> I may need to readup on stylesheet however, this is just the problem I am
> seeing, and don't know what other issue may crop up using this script.
>
> Thanks,
> Keith
>
>

Mime
View raw message