Search code examples
xmljsontalend

Convert multilevel xml to json in talend


Here is the code:

<labels>
<label><id>1</id><name>Planet E</name><contactinfo>Planet E Communications P.O. Box 27218 Detroit, 48227, USA p: 313.874.8729 f: 313.874.8732 email: info AT Planet-e DOT net
 </contactinfo><profile>Classic Techno label from Detroit, USA. [b]Label owner:[/b] [a=Carl Craig].
</profile><data_quality>Needs Vote</data_quality><urls><url>http://planet-e.net</url><url>http://planetecommunications.bandcamp.com</url><url>http://www.discogs.com/user/planetedetroit</url><url>http://www.facebook.com/planetedetroit</url><url>http://www.flickr.com/photos/planetedetroit</url><url>http://plus.google.com/100841702106447505236</url><url>http://myspace.com/planetecom</url><url>http://myspace.com/planetedetroit</url><url>http://soundcloud.com/planetedetroit</url><url>http://twitter.com/planetedetroit</url><url>http://vimeo.com/user1265384</url><url>http://www.youtube.com/user/planetedetroit</url><url>http://en.wikipedia.org/wiki/Planet_E_Communications</url></urls><sublabels><label>Antidote (4)</label><label>Community Projects</label><label>Guilty Pleasures</label><label>I Ner Zon Sounds</label><label>Planet E Communications, Inc.</label><label>TWPENTY</label></sublabels></label>
 <label><id>2</id><name>Earthtones Recordings</name><contactinfo>Seasons Recordings
2236 Pacific Avenue
Suite D
Costa Mesa, CA  92627

tel: +1.949.574.5255
fax: +1.949.574.0255

email: &lt;a href="mailto:[email protected]"&gt;[email protected]&lt;/a&gt;
   </contactinfo><profile>California deep house label founded by Jamie Thinnes. Now defunct and continued as [l=Seasons Recordings].</profile> <data_quality>Correct</data_quality><urls><url>http://www.seasonsrecordings.com/</url></urls></label></labels>

I tried twritejsonfield but it doesn't preserve the multilevel hierarchy. Please help


Solution

  • I used an external library instead. Json-lib. I passed the xml row after row and had it converted to json and saved the json in a simple file with a json extension.