I thought XML is highly portable and can be used as a mini database. I have seen XML used everywhere. I even see large companies switching over to JSON. Even Microsoft has integrated support for JSON. What is all the hype over JSON?
相关问题
- Jackson Deserialization not calling deserialize on
- Illegal to have multiple roots (start tag in epilo
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- How to fix IE ClearType + jQuery opacity problem i
XML doesn't really begin to shine until you start mixing together different namespaced schemas. Then you see JSON start to fall down, but if you just need a serialization format for your data, JSON is smaller, lighterweight, more human readable, and generally faster than XML.
Just an anecdote from my own personal experience:
I wrote a small Javascript directory, first with the data in XML, and then adapted it to use JSON so I could run them side-by-side and compare speeds with Firebug. The JSON ended up being approximately 3 times faster (350-400 ms vs. 1200-1300 ms to display all data). Also, as others have noted, the JSON is much easier on the eyes and the file size was a good 25% smaller due to the leaner markup.
I'm no expert by far but from the various companies I've worked for we generally use XML in small data environments or configuration values (web.config is a great example).
When you have large amounts of data, generally, you will want to report on that data. And XML is not a great source for reporting. In the grand scheme of things, it seems as though a transactional database is easier to report/search against than XML.
Does this make sense? As I said above, I'm no expert but from my experience this seems to be the case. Also, I believe Microsoft integrated JSON support due to the wave of developers moving over to client-side or scripted actions to enhance the visuals of the UI (Ajax) and Microsoft's Ajax has not been used as much as other libraries like jQuery and MooTools (Yahoo's YUI is also in that mix) due to their beautiful integration of serializable objects using JSON.
I find myself writing code now implementing the JSON serializer in my VB code. It's WAY too easy and from an upgrading/modifying standpoint, you can't beat it. It's Microsoft's way of keeping us addicted to VS I guess. I have recently converted an enterprise application to using Ajax (via jQuery) and using JSON format. It took approximately 2 weeks to do so. I actually thank Microsoft for integrating it because without it, I would have had to write quite a bit of extra code.
Now that there are JSON encoders and decoders for most languages, there's no reason NOT to use JSON for uses where it makes sense (and that's probably 90% of the use cases for XML).
I've even heard of JSON strings being used in large SQL databases to make schema changes easier.
Basically because JSON is recognized natively by JavaScript, it's really lightweight, minimalistic and highly portable because it relies only on two fundamental structures:
One major advantage other than the ones mentioned here. For the same data, there are multiple ways to represent it as a XML file but only one way with JSON, removes ambiguity :)