XML to JSON - losing root node
Posted
by Mike
on Stack Overflow
See other posts from Stack Overflow
or by Mike
Published on 2010-03-19T04:26:37Z
Indexed on
2010/03/19
4:31 UTC
Read the original article
Hit count: 200
I'm using net.sf.json with a Java project and it works great.
The conversion of this XML:
<?xml version="1.0" encoding="UTF-8"?>
<important-data certified="true" processed="true">
<timestamp>232423423423</timestamp>
<authors>
<author>
<firstName>Tim</firstName>
<lastName>Leary</lastName>
</author>
</authors>
<title>Flashbacks</title>
<shippingWeight>1.4 pounds</shippingWeight>
<isbn>978-0874778700</isbn>
</important-data>
converts to this in JSON:
{
"@certified": "true",
"@processed": "true",
"timestamp": "232423423423",
"authors": [ {
"firstName": "Tim",
"lastName": "Leary"
}],
"title": "Flashbacks",
"shippingWeight": "1.4 pounds",
"isbn": "978-0874778700"
}
However, the root tag
<important-data>
is lost in the conversion. Being new to XML and JSON, I am not sure if this is suppose to be the correct behaviour. If not, is there any way to tell net.sf.json to convert it while keeping the root node property?
Thanks.
© Stack Overflow or respective owner