This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Clojure and the fly likes xml to JSON conversion issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Clojure
Bookmark "xml to JSON conversion issue" Watch "xml to JSON conversion issue" New topic
Author

xml to JSON conversion issue

Harish Maridi
Ranch Hand

Joined: May 20, 2008
Posts: 60
Hi,

I have following xml that I am looking to convert it to JSON, I am using XML.java class to convert, method toJSONObject(xml), Posted code below. braces are missing from different places.
Please let me know if my xml format is bad or is there anything I am missing.

Output that I am getting:
"orgInfo":"genesisId":,"regionName":"SALES ADMIN REGION","areaName":"SALES ADMIN","branchNumber":"088","branchName":"AV/ELECTRO AIR","areaId":"96","partyId":"1646171","jobRole":,"regionId":"96","jobRoleAcronym":},"managerInfo":"contactInfo":"eMail":,"name":"middle":,"last":,"salutation":,"first":},
"addressList":"address":"streetAddress3":,"streetAddress2":,"streetAddress1":,"zip":,"state":,"city":,"country":},"addressType":"Business"},"fax":},"employeeId":"38075"},
"contactInfo":"eMail":"harish.maridi@av.com","name":"last":"Maridi","first":"Harish"},"addressList":"address":"streetAddress3":,"streetAddress2":,"streetAddress1":,"zip":,
"state":,"city":,"country":},"addressType":"Business"},"phoneList":"phoneType":"Work","number":,"extension":}},"employeeId":"10031"}

Desired output::
{"orgInfo":{"genesisId":{},"regionName":"SALES ADMIN REGION","areaName":"SALES ADMIN","branchNumber":"088","branchName":"AV/ELECTRO AIR","areaId":"96",
"partyId":"1646171","jobRole":{},"jobRoleAcronym":{},"regionId":"96"},"managerInfo":{"contactInfo":{"eMail":{},"name":{"middle":{},"last":{},"salutation":{},"first":{}},
"addressList":{"address":{"streetAddress3":{},"streetAddress2":{},"streetAddress1":{},"zip":{},"state":{},"country":{},"city":{}},"addressType":"Business"},"fax":{}},
"employeeId":"38075"},"contactInfo":{"eMail":"harish.maridi@av.com","name":{"last":"Maridi","first":"Harish"},"addressList":{"address":{"streetAddress3":{},"streetAddress2":{},
"streetAddress1":{},"zip":{},"state":{},"country":{},"city":{}},"addressType":"Business"},"phoneList":{"phoneType":"Work","number":{},"extension":{}}},"profile":"authenticated","employeeId":"10031"}

Source XML::
<?xml version="1.0" encoding="UTF-8"?>
<ns3:queryEmployee xmlns:ns3="http://www.av.com/qryemp">
<queryEmployeeRequest>
<employeeId>10031</employeeId>
<getCustomerListFlag>false</getCustomerListFlag>
<getSupplierListFlag>false</getSupplierListFlag>
<msgCorrelationId>001</msgCorrelationId>
<getManagerInfoFlag>false</getManagerInfoFlag>
<getReporteesFlag>false</getReporteesFlag>
</queryEmployeeRequest>
<queryEmployeeResponse>
<employeeId>10031</employeeId>
<managerInfo>
<employeeId>38075</employeeId>
<contactInfo>
<eMail/>
<fax/>
<name>
<salutation/>
<first/>
<last/>
<middle/>
</name>
<addressList>
<addressType>Business</addressType>
<address>
<country/>
<zip/>
<state/>
<city/>
<streetAddress3/>
<streetAddress2/>
<streetAddress1/>
</address>
</addressList>
</contactInfo>
</managerInfo>
<contactInfo>
<eMail>harish.maridi@av.com</eMail>
<name>
<first>Harish</first>
<last>Maridi</last>
</name>
<addressList>
<addressType>Business</addressType>
<address>
<country/>
<zip/>
<state/>
<city/>
<streetAddress3/>
<streetAddress2/>
<streetAddress1/>
</address>
</addressList>
<phoneList>
<phoneType>Work</phoneType>
<number/>
<extension/>
</phoneList>
</contactInfo>
<orgInfo>
<jobRole/>
<jobRoleAcronym/>
<genesisId/>
<partyId>1646171</partyId>
<regionId>96</regionId>
<regionName>SALES ADMIN REGION</regionName>
<areaId>96</areaId>
<areaName>SALES ADMIN</areaName>
<branchNumber>H88</branchNumber>
<branchName>AV/ELECTRO AIR</branchName>
</orgInfo>
</queryEmployeeResponse>
</ns3:queryEmployee>

Code of XML.java
Sean Corfield
Ranch Hand

Joined: Feb 09, 2011
Posts: 252
    
    5

This doesn't appear to be a Clojure question - why is it posted here?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Indeed. I scanned through it but then decided not to post because I know nothing about Clojure and didn't want to make a fool of myself. Perhaps others felt the same way.

Perhaps the OP could report the post and ask for it to be moved into a more suitable forum?
Harish Maridi
Ranch Hand

Joined: May 20, 2008
Posts: 60
Moved to XML forum, posted here due to my overlook.

Thanks,
HM
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: xml to JSON conversion issue
 
Similar Threads
Cyclomatic Complexity Calculation
getting Nulpointer in xml file parsing
Struts and JSON
Getting different time than system time in Unix (java.util.Date)
Expression based Json Query Engine