0

I have recently started using JSON and was wondering if I am missing any other important reasons as to why I would use a JSON object instead of just returning a large string of data.

Here is what I have found so far: A JSON object is a lot faster to process, easier to handle and parse. A JSON object is easier for a human to read compared to a big string of data output. JSON objects can be mapped easier and works well with object oriented systems.

  • When you say, "large string of data" - are you talking about a specific format? xml? JSON strings can also be quite large. – Sam Dufel May 02 '14 at 20:37
  • I was comparing to XML. – user3597582 May 02 '14 at 21:56
  • Hello, welcome to SO. The question should be clear all by itself, without the comments. Can you please edit the question to include the information you put in that comment, as well as anything else that would make it more clear? Thanks! – Wayne Conrad May 02 '14 at 23:15

1 Answers1

2

JSON is just a [large] string of data.

The difference from a one-off/custom "blob'o'test" encoding is that JSON is a well-defined format that supports common ADTs (Arrays, Maps) and is a useful interchange format. Also, one doesn't work with JSON (which is just text) directly; one works with the object-graphs that are serialized to/from JSON - e.g. once you call JSON.parse(jsonText) you're dealing with regular objects.

While XML is another well-defined format, JSON has a better 1-1 mapping with simple object-graphs. This easier mapping eliminates the need for a specific DOM wrapper or other specialized access - who wants to deal with an object model when one can treat an object-graph as first-class data?1

The fact that JSON (which is just text) also looks like normal JavaScript Object Literal Notation (and excluding some odd Unicode issues, is a subset) makes human consumption relatively easy and has greatly helped the adoption.

Refer to the following questions for additional insight on "What?" and "Why?"


1 XML is much more than a simple markup format, but comparing XML to JSON in any more detail is outside the scope of the question.

Community
  • 1
  • 1
user2864740
  • 60,010
  • 15
  • 145
  • 220