Convert XML to JSON in mediation route

Nine Stars

Convert XML to JSON in mediation route

Hi,

 

I would like to transform an XML to JSON in a route.

 

I created a basic route:

Capture.PNG

 

With my first cFile, I pick up a XML file.

 

In my cJavaDSLProcessor, I entered (According to http://camel.apache.org/xmljson.html):

Capture.PNG

 

And my second cFile component is supposed to put down my JSON file.

 

In my cConfig component, I added this jar:

-camel-xmljson-alldep-2.16.3.jar

 

  

 But I get this exception "java.lang.NoClassDefFoundError: nu/xom/Serializer" when running the route...

 

Eric


Accepted Solutions
Nine Stars

Re: Convert XML to JSON in mediation route

I fixed the issue adding these three jars:

-xom-1.2.7.jar (Without it I have this exception "java.lang.NoClassDefFoundError: nu/xom/Serializer"
-commons-lang-2.6.jar (Without it I have this exception "java.lang.NoClassDefFoundErrorSmiley Surprisedrg/apache/commons/lang/exception/NestableRuntime" )
-commons-collections-3.2.2.jar (Without it have this exception "java.lang.ClassNotFoundException: org.apache.commons.collections.map.ListOrderedMap")

 

It works now.

 

Eric


All Replies
Nine Stars

Re: Convert XML to JSON in mediation route

I fixed the issue adding these three jars:

-xom-1.2.7.jar (Without it I have this exception "java.lang.NoClassDefFoundError: nu/xom/Serializer"
-commons-lang-2.6.jar (Without it I have this exception "java.lang.NoClassDefFoundErrorSmiley Surprisedrg/apache/commons/lang/exception/NestableRuntime" )
-commons-collections-3.2.2.jar (Without it have this exception "java.lang.ClassNotFoundException: org.apache.commons.collections.map.ListOrderedMap")

 

It works now.

 

Eric

Five Stars

Re: Convert XML to JSON in mediation route

Hi Eric,

Hi,

I have an xml which contains some tags empty ,i want to populate this empty tags(</city>) with some value like 'NNNNNNNNNNN' and generate an xml as output(<city>NNNNN</city>).I am using tadvancedxmloutput command and Talend open studio for big data, but i was able to loop only one sub element at a time,can some one help how to process this.

Below are my xml input and expected xml output format.

 

input xml :::::::::

<emp>
<id>985426</id>
<fname>jai</fname>
<lname>singh</lname>
<listofaddress>
<address>

<street>college street</street>
<city>bangalore</city>
<state>karnatka</state>
<datestayed>04-01-2015 - 07-08-2015</datestayed>
</address>
<address>

<street>pakala street</street>
<city>Hyd</city>
</state>
<datestayed>07-10-2015 - 10-08-2017</datestayed>
</address>

<address>
</street>
<city>chennai</city>
<state>TN</state>
<datestayed>10-08-2017</datestayed>
</address>

</listofaddress>

<Comments>
<Comment>
<Mgrcomment>skiled labor</Mgrcomment>
<employeecomment>satisfied work</employeecomment>
<leadcomment>hard worker</leadcomment>
<clientcomment>satisfied work</clientcomment>
<place>bangalore</place>
</Comment>

<Comment>
<Mgrcomment>excellent communications</Mgrcomment>
<employeecomment>hard worker</employeecomment>
<leadcomment>need to improve skill set</leadcomment>
</clientcomment>
<place>bangalore</place>
</Comment>


<Comment>
<Mgrcomment>keep going</Mgrcomment>
</employeecomment>
<leadcomment>keep moving</leadcomment>
</clientcomment>
<place>Hyd</place>
</Comment>
</Comments>
</emp>


expected output xml::::::::::

<emp>
<id>985426</id>
<fname>jai</fname>
<lname>singh</lname>
<listofaddress>
<address>

<street>college street</street>
<city>bangalore</city>
<state>karnatka</state>
<datestayed>04-01-2015 - 07-08-2015</datestayed>
</address>
<address>

<street>pakala street</street>
<city>Hyd</city>
<state>NNNNNNNNNNNNNNNNNNNNN</state>
<datestayed>07-10-2015 - 10-08-2017</datestayed>
</address>

<address>
<street></street>
<city>chennai</city>
<state>TN</state>
<datestayed>10-08-2017</datestayed>
</address>

</listofaddress>

<Comments>
<Comment>
<Mgrcomment>skiled labor</Mgrcomment>
<employeecomment>satisfied work</employeecomment>
<leadcomment>hard worker</leadcomment>
<clientcomment>satisfied work</clientcomment>
<place>bangalore</place>
</Comment>

<Comment>
<Mgrcomment>excellent communications</Mgrcomment>
<employeecomment>hard worker</employeecomment>
<leadcomment>need to improve skill set</leadcomment>
<clientcomment>NNNNNNNNNNNNNNNNNNNNN</clientcomment>
<place>bangalore</place>
</Comment>


<Comment>
<Mgrcomment>keep going</Mgrcomment>
<employeecomment>NNNNNNNNNNNNNNNNNNNNN</employeecomment>
<leadcomment>keep moving</leadcomment>
<clientcomment>NNNNNNNNNNNNNNNNNNNNN</clientcomment>
<place>Hyd</place>
</Comment>
</Comments>
</emp>

Five Stars

Re: Convert XML to JSON in mediation route

Hi Eric,

 

Ihave this error can you help me please ?

 

Capture.PNGerreurJsonClassNotFFound.PNG

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads