5 ms·
> JSON exists only because it was basically the JS literal syntax, and people needed easy ways to instantiate javascript objects. JSON is an interchange format
by BinaryIdiot 10y ago
> JSON exists only because it was basically the JS literal syntax, and people needed easy ways to instantiate javascript objects.
JSON is an interchange format that, while it's based off a subset of JavaScript, was created as the authors were looking for a way to send data between the browser and the server without Flash swifts or Java applets that was small and easy to use and since JavaScript was already there they just lifted that.
I'm not sure I get the "needed easy ways to instantiate javascript objects". I don't see that anywhere and ECMAScript 3 was out at the time which let you instantiate them pretty easily. So maybe I misunderstand your meaning?
- flukus 10y ago> a way to send data between the browser and the server without Flash swifts or Java applets that was small and easy to use And because they hated angle brackets. XML already filled that void.
- BinaryIdiot 10y agoXML wouldn't have filled the void well for JavaScript though. Their goal was to send data back and forth and would ultimately need to be processed and rendered by JavaScript. Easiest way to do that is to just send a JavaScript object back and forth. It would have been a lot cheaper to parse JSON into JavaScript objects especially back then on the more limited hardware than trying to parse XML.
- ttepasse 10y agoPretty soon with the birth of JSON everyone stopped using eval() because of obvious security concerns (eval is evil) and JSON parsers before JSON.parse() were doing the heavy lifting handwritten in JS. That was also the time when XML/XHTML on the web wasn't as disregarded as today. Browsers are XML parsing software. They exposed JS Interfaces for these XML parsers. And a query interface. And the DOM. Etc. My thesis: The data to send mostly matches a tree of structs and arrays and values which we use in programming languages. XML is not the perfect vessel for that, it's better used as a document format. XML of course was misused as a configuration format in the decade before, leading to the backlash.
- flukus 10y ago> XML wouldn't have filled the void well for JavaScript though This isn't hypothetical. It did fill that void before we had JSON, it's what the X in AJAX stood for. Browsers were parsing xml before javascript existed. In hindsight, JSON was the first sign of the wheel reinvention that was to come from the javascript world.
- BinaryIdiot 10y agoI think you missed the "well" in my quote (no one said it was hypothetical). Naturally the XMLHttpRequest / AJAX was used with XML first. Microsoft were the ones to introduce it to do exactly that; work with their exchange server's XML. This is why I said "well". XML isn't a perfect fit into JavaScript's existing objects. It's awkward. Mozilla, imperfectly, copied the interface Microsoft came up with to have a sort of standard and 4 months after that Crockford started using JSON[1]. I don't see much history of applications beyond Microsoft's and a few edge cases that really used XML here; most of what I can find online had a lot of people's first usage of AJAX with JSON or plain text. But I'll admit it's very difficult to find solid data. But ultimately XMLHttpRequest came out, in its very first ActiveX form in IE, in March 1999 and Crockford started playing with JSON in April 2001. Wikipedia claims XMLHttpRequest didn't become a de facto standard until 2004 when other browsers started adopting it[2] so I'm not convinced it was used for very much XML to begin with. [1] https://www.youtube.com/watch?v=-C-JoyNuQJs https://www.youtube.com/watch?v=-C-JoyNuQJs [2] https://en.wikipedia.org/wiki/XMLHttpRequest https://en.wikipedia.org/wiki/XMLHttpRequest
- taeric 10y agoActually, the easiest way is to just send HTML down to the browser. This was the rallying cry of XHTML for a while. You have client side code that calls for an update to a section of the page, and the framework sends down the necessary html to replace it.
- taeric 10y agoIt was common to inline a server object into a script tag using the literal syntax. As you say, this used the literal syntax that was supported at the time. Ajax came and provided async to get data. But the rendering of the page also has dynamic data, and there it has long been easy to put data into objects.