1

More and more, I see JSON being used to:

  1. Communicate between server-side processes.
  2. Serialize and store data.

What is the benefit to using JSON over XML in these situations?

JSON's original benefit was that it serialized directly into Javascript objects, thus easing Ajax programming when working with Javascript client-side (server-side Javascript programming would clearly benefit too, relatively rare as it is).

But XML has a large history, and an ecosystem of supporting technologies and protocols (XSL, XSLT, XInclude, XQuery, XPath, XML Schema, serialization support, etc.). Why is JSON infiltrating the non-Javascript world (and data serialization), when it simply seems to be duplicating the role that XML has historically played, but without all the support technology and work that it's taken XML decades to develop?

When I choose XML over JSON in serialization and communication situations that don't use Javascript in any way, I seem to be going against a growing trend. What am I missing?

Edit: My question is not solely about parsing speed (though that might be one factor). My question is more about the lack of supporting technologies and protocols in JSON which have existed in XML for years, and why the technology community felt the need to re-invent this particular wheel.

Deane
  • 8,269
  • 12
  • 58
  • 108
  • This question is a possible duplicate of [JSON and XML comparison](http://stackoverflow.com/questions/4862310/json-and-xml-comparison), which discusses JSON vs. XML performance in a variety of languages – Aaron Brager Sep 21 '15 at 13:54
  • Some more discussion (with benchmarking data) here: http://www.codeproject.com/Articles/604720/JSON-vs-XML-Some-hard-numbers-about-verbosity – Aaron Brager Sep 21 '15 at 13:55
  • Java is easily viewable in webpages and is more secure since connection can use proxies and certificates. Java can run scripts that may contain viruses while xml has no viruses. – jdweng Sep 21 '15 at 13:56
  • 3
    @jdweng Java has nothing to do with XML or JSON at all. Also you're comparing the programming language and data format, so apples and pears. Doesn't make a sense at all. – David Ferenczy Rogožan Sep 21 '15 at 14:07
  • I would argue the fact that Java and Jason have nothing to do with each other. I just specified characteristics of each. I didn't want to get into the issue of which is more secure and even if it needs to be secure because different people have different opinions on net security. – jdweng Sep 21 '15 at 14:49
  • 1
    @jdweng JSON is **JavaScript Object Notation**. "Jason" is nonsense. JavaScript has nothing to do with Java. XML and JSON are just a data formats, they can't be secure or insecure. – David Ferenczy Rogožan Sep 21 '15 at 14:58
  • @jdweng ["Java is to JavaScript as ham is to hamster"](http://www.seguetech.com/blog/2013/02/15/java-vs-javascript) – David Ferenczy Rogožan Sep 21 '15 at 15:03
  • And Jason code can call Java!!! – jdweng Sep 21 '15 at 17:07

2 Answers2

0

I would say, that using JSON is just often simpler even if you don't have so many tools as you have for XML. Also JSON is often just enough, you don't need things like XSLT to store configuration or exchange some hierarchical data. So in fact it actually fits this purpose better than XML.

Plus you have also some benefits like better performance, better readability for humans, less data etc.

But there are fields where XML definitely fits better than JSON of course. Like for example document generation using XSLT.

David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
  • The benefits you mention are slight. I'm curious if it was worth introducing an entirely different protocol with huge amounts of overlap and fracturing the development community for such a small benefit. – Deane Sep 21 '15 at 15:12
  • Benefits I mentioned don't explain, why JSON was created, they are just trying to answer OP's question (why it's used for inter-process communication or data storage). You can read why it was created for example on [Wikipedia](https://en.wikipedia.org/wiki/JSON). – David Ferenczy Rogožan Sep 21 '15 at 15:17
  • @Deane BTW I think the fact that JSON is used "everywhere" these days, tells a lot about if it was worth creating an entirely different protocol (it's rather data format than protocol). It's used for configuration storage, data exchange (APIs), even major databases support it, and a lot more. – David Ferenczy Rogožan Sep 21 '15 at 15:23
  • But major databases have supported XML for years. I feel like we've gone full circle for no good reason. I can't see how we're actually any better off than we were before, and we've spent considerable time, effort, and attention getting...nowhere. – Deane Sep 21 '15 at 15:52
  • @Deane Then just use XML, if you don't see any reason to use JSON. Nobody is forcing you to use JSON. The fact, that majority is using JSON instead of XML these days is because they see a lot of benefits there. I don't understand why are you arguing about that. – David Ferenczy Rogožan Sep 21 '15 at 16:04
  • Because I want to understand the benefits to make sure I'm not using XML when I should be using JSON. I'm still not getting it, I guess. – Deane Sep 21 '15 at 16:07
  • Basically JSON wasn't created as a replacement of XML. It's **JavaScript Object Notation**. But it fits to a lot of purposes so better than XML, that it was adopted there. It wasn't like "*hey, we created another new data format, lets use it! (with no reason)*", it was more like "*hey, this JavaScript's Object Notation looks good, it would be better for my XYZ than XML, I'll use it*". Google "JSON vs XML" and read some articles. E.g. https://blog.udemy.com/json-vs-xml/ – David Ferenczy Rogožan Sep 21 '15 at 16:15
0

Based on your edits and comments, for example:

My question is more about the lack of supporting technologies and protocols in JSON which have existed in XML for years, and why the technology community felt the need to re-invent this particular wheel.

and:

I'm curious if it was worth introducing an entirely different protocol with huge amounts of overlap and fracturing the development community for such a small benefit.

...it seems like you are coming at this from the .Net/Java perspective (where things like "compiling code" and "IDE's" are common). But because JSON came out of the javascript world, I believe its popularity stems from its appeal to people who are NOT in the .Net/Java ecosystem (so people using dynamic languages -- ruby, python, php etc.).

For better or worse, there seems to be an underlying attitude amongst people who use dynamic languages for web development that all the Java/.Net stuff is too "heavy-weight", so for them it's actually more appealing to have something that doesn't require all that tooling; which can be more easily understood just by looking at it; for which parsers can be more easily written; and for which you can just output a string without having to learn a bunch of other systems.

I'm guessing that the popularity of JSON for web-facing systems then became so great amongst the dynamic languages that .Net/Java ecosystems had no choice but to get on board in order to be interoperable with the newer web-based systems.

Jordan Lev
  • 2,773
  • 2
  • 26
  • 39