Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>JSON came into popular use primarily because it offers a way to circumvent the same-origin policy used in web browsers and thereby allow mashups.</p> <p>Let's say you're writing a web service on domain A. You can't load XML data from domain B and parse it because the only way to do that would be XMLHttpRequest, and XMLHttpRequest was originally limited by the same-origin policy to talking to only URLs at the same domain as the containing page.</p> <p>It turns out that for a variety of reasons, you <em>are</em> allowed to request &lt;script&gt; tags across origins. Clever people realized this was a good way to work around the limitation with XMLHttpRequest. Instead of the server returning XML, it can return a series of JavaScript object and array literals.</p> <p>(bonus question left as an exercise to the reader: why is &lt;script src="..."&gt; allowed across domains without server opt-in but XHR isn't?)</p> <p>Of course, returning a &lt;script&gt; which consists of nothing more than object literals is not useful because without assigning the values to some variable, you can't do anything with it. Thus, most services use a variant of JSON, called JSONP (<a href="http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/" rel="nofollow noreferrer">http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/</a>).</p> <p>With the rise in popularity of mashups, people realized that JSON was a convenient data interchange format in general, especially when JavaScript is one end of the channel. For example, JSON is used extensively in Chromium, even in cases where C++ is on both sides. It's just a nice lightweight way to represent simple data, that good parsers exist for in many languages.</p> <p>Amusingly, using &lt;script&gt; tags to do mashups is incredibly insecure because it is essentially XSS'ing yourself on purpose. So native JSON (<a href="http://ejohn.org/blog/native-json-support-is-required/" rel="nofollow noreferrer">http://ejohn.org/blog/native-json-support-is-required/</a>) had to be introduced, which obviates the original benefits of the format. But by that time, it was already super popular :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload