David Pollak (from Lift): “There’s no way to convert from XML to JSON because XML contains sequences not expressible in JSON”
Hmm[*]. Not sure if this is true (with CDATA, #Text and @attributes handled in some converters). For me the problem is more that there are too many ways to convert XML to JSON. For exampe the Badgerfish convention. Or the the Google and Yahoo versions. Or the XML.com way. And the Parker convention.
But the ways in Javascript to convert XML to JSON are either slow, very basic, use XSLT, use nasty Regex or cannot create simple JSON which feels JSON like.
* Note to self: Should start using Twitter for this [**].
** Did start Twitter
Update: Any ideas for a good XML to JSON conversion which feels JSON like (no need to be bidirectional)?
Update 2: I currently use XSLT with nice results, Safari doesn’t work yet and neither does Chrome. More to come.
You can leave a Reply here. Of course, you should follow me on twitter here.
I’m not sure what the intent of your blog post is. Clearly
mappings between XML and JSON exists (I’m pretty sure some
geek out there has done a language equivalence proof, at
least to some extent) and as you state multiple
converters/conventions exist. I don’t agree that there are
too many ways out there.
There are many ways to do XML to JSON (and visa versa)
because there are many reasons to do so. Some reasons deal
with huge amounts of data, rendering client side
conversion too slow, some deal with small data amounts
clearly favouring a clientside/javascript implementation.
One has to remember that XML and JSON however deal with
two very distinct areas of interest. XML is very good to
handle document structures and JSON is great for dealing
with data structures. I find XML to JSON particularly
interesting with regards to data structures.
So, in my oppinion, the exchangeability from XML to JSON is useful and definetly here to stay.
Microsoft Visual Studio has the capability to serialize
all objects to XML and JSON (natively supported) – or any
other custom format that would be able to map from a
serializeable object.
See http://msdn.microsoft.com/en-
us/library/system.runtime.serialization.json.datacontractj
sonserializer.aspx
So going from eg. a C# object to either XML or JSON and
then back to the original C# object is possible.
For an example, see:
http://pietschsoft.com/post/2008/02/NET-35-JSON-Serialization-using-the-DataContractJsonSerializer.aspx
Best regards,
Michael