Live data from Hacker News

Why is JSON so popular? Developers want out of the syntax business

stereolambda.wordpress.com

81–90 of 120 posts

Re: Why is JSON so popular? Developers want out of the syntax business

#81
post #36
post #26

The "XML requires you to build your own parse tree" argument isn't valid; XML libraries are fully capable of handing you a DOM-style tree, and of allowing you to pull things out of the tree without writing your own traversal code. JSON just assumes messages are going to trivially fit into naive data structures, and so provides fewer options.

I'm not sure if you are complaining about this aspect, but I would observe that "fewer options" is actually the feature here, not the bug. A generic XML DOM is still complicated to deal with. Even if you do the "right thing" and use XPath, you still have to deal with XPath because you can't get around the fact that you have an underlying representation that has at least two dimensions (attributes vs. CDATA). That is,…

The only thing I miss when using json are the css selectors when trying to find data in a nested structure.

With json I have to resort to imperative means and care about the middle layers. That means refactorings are more likely to break software.

Fundamentally there is no reason why json cannot have it's own selector which traverses the tree. There just isn't one that I know of though.

Re: Why is JSON so popular? Developers want out of the syntax business

#82
post #4

As one of the earlier commenters pointed out, lisp welcomes you to the 1960s.

Yeah, sure. S-expresssions are literals in Lisp, and can be "parsed" calling eval. But I think that misses the larger point made by the OP. JSON is really useful even in languages other than Javascript. JSON wins over XML because XML is too complex and thus ambiguous. But JSON wins over s-expressions too, because s-expressions are too simple. How do you represent John Smith as an s-expression? Sure, it can be done. But as with XML, software that consumes s-expressions has to know how to interpret their structure, even if it doesn't have to parse the surface syntax.

Re: Why is JSON so popular? Developers want out of the syntax business

#83
post #64
post #58

Earlier quoted context omitted.

You know, I know we're just geeking out here so please don't read too much into me taking the devil's advocate position, but: yes, XML is harder to parse , but the underlying data that gets encoded in JSON and XML isn't substantially different. In both cases --- and let's take the C implementation case --- you're still building a poorly specified buggy implementation of Tcl to actually hold the data and answer questi…

Dunno why you got downmodded there.. Anyways, if they're equivalent, and JSON is both easier to parse and has a far higher data density.. why would anyone ever use XML for anything?

Three-legged races are fun.

Re: Why is JSON so popular? Developers want out of the syntax business

#84
post #18

Isn't it dangerous to eval()? Suppose someone put some malicious code in the JSON data?

The question to ask is: is the JSON coming from a trusted source (e.g. generated by your server and you can reasonably sure that you have no funny XSS holes)? If the answer is yes, eval()-ing JSON is perfectly safe. If the answer no, you need to parse it without the help of the JS interpreter.

And you should probably err on the safe side.

Re: Why is JSON so popular? Developers want out of the syntax business

#85
The argument is always the same, and the JSON crowd always assert "superiority" derived from sheer simplicity. XML is too hard for them, and they're part of some bizarre quasi-political movement that trashes object-oriented principles. Thus, 'simple' trumps validation via type, version control (and hence interoperability over time without breakage and maintenance), robustness.

The weakness in the Javascript "eco-system" is it's quasi (the 'quasi' qualifier applies frequently in this eco-system) support of objects. XSD/XML is powerful when used in an object paradigm, and object paradigms have proven (not just via community claims) to be very effective.

The question is, when will the JS community step up to the plate (i.e. mature)? So much energy is wasted now on making JSON work -- just in order to make Javascript easy. Wrong priorities.

Re: Why is JSON so popular? Developers want out of the syntax business

#86
post #82
post #4

As one of the earlier commenters pointed out, lisp welcomes you to the 1960s.

Yeah, sure. S-expresssions are literals in Lisp, and can be "parsed" calling eval. But I think that misses the larger point made by the OP. JSON is really useful even in languages other than Javascript. JSON wins over XML because XML is too complex and thus ambiguous. But JSON wins over s-expressions too, because s-expressions are too simple. How do you represent John Smith as an s-expression? Sure, it can be done. B…

It's true that s-expressions don't give you a literal syntax for hashmaps or arrays, but note that some lisps (e.g. Clojure) do support these natively … and in a syntax that's better than JSON since you don't have to type all those annoying commas ;-)

Re: Why is JSON so popular? Developers want out of the syntax business

#87
post #86
post #82

Earlier quoted context omitted.

Yeah, sure. S-expresssions are literals in Lisp, and can be "parsed" calling eval. But I think that misses the larger point made by the OP. JSON is really useful even in languages other than Javascript. JSON wins over XML because XML is too complex and thus ambiguous. But JSON wins over s-expressions too, because s-expressions are too simple. How do you represent John Smith as an s-expression? Sure, it can be done. B…

It's true that s-expressions don't give you a literal syntax for hashmaps or arrays, but note that some lisps (e.g. Clojure) do support these natively … and in a syntax that's better than JSON since you don't have to type all those annoying commas ;-)

You know I never quite got that comma thing. For instance in python, the only reason it is necessary is because {"foo": "bar" "baz", 'k2':'v2'} is the same as {'foo':'barbaz', 'k2':'v2'}. Getting rid of auto-concatination allows for {'foo':'barbaz' 'k2':'v2'} which is pretty easy to parse base on tokens and ':'. It also eliminates a pretty common bug, in which there is kv pair per line, and the line ends with ',', except for the last line which does not have the ','. (The following line has a '}'). The common bug being adding a new kv pair and missing the ','.

Re: Why is JSON so popular? Developers want out of the syntax business

#88

The argument that XML can have various different structures for storing a person's name, while JSON provides one simple solution, doesn't fly. You could run into something like { "Person": { "property": { "type": "first-name", "value": "John" }, "property": { "type": "last-name", "value": "Smith" } } } This begs the question, "Why would you do something that convoluted?" Well, you can ask the same of the XML examples…

My gut feeling on this is that almost anyone can recognize that writing JSON like that is wrong. However, trying to determine if is better than John Smith is often very difficult. In the wild, I've seen both strategies used depending on the situation.

Actually it's very simple. If you don't need children don't make them. I measured it once and storing stuff in attributes had ~10 times faster parsing in MSXML.

Re: Why is JSON so popular? Developers want out of the syntax business

#89
post #4

As one of the earlier commenters pointed out, lisp welcomes you to the 1960s.

Not enough data types in CL or Scheme's reader (Clojure wins here) and no standard between the lisps.

But, there was something Lisp did right that no other mainstream scripting language has - it separated the reader and the evaluator. You can eval Perl or Ruby or Python, but not securely read it. This goes for Javascript too - you can eval a JSON, but you'd be an idiot.

Re: Why is JSON so popular? Developers want out of the syntax business

#90
post #6
post #4

As one of the earlier commenters pointed out, lisp welcomes you to the 1960s.

Sorry we were late to the party, guys, we just got so wrapped up in writing software that people actually use.

Put differently: if the goal is making money, lisp is frequently not the best choice.
Post reply on HN