News for hackers. Stuff that matters.
Re:Why is JSON so popular? Developers want out of the syntax... by jerf on Friday March 19, 2010 @11:11AM (#1204287)
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, just as the article says, you have more degrees of freedom in how you represent your data, and what is a "degree of freedom" but a near synonym of "dimensionality"? You can't abstract around dimensionality very effectively without losing fundamental capabilities in the underlying component (in fact a staggering number of abstraction failures in general can be shown to come from exactly this problem if you really learn to think this way), and the complexity comes poking out in the XPath. It's still better than groveling over the DOM yourself, but it's probably also the absolute peak of concision that is obtainable; there will be nothing better.

JSON is indeed simpler in that you don't really have 3 or 4 feasible choices per attribute; {"first-name": "John", "last-name": "Smith"} is pretty much your choice, full stop. That leaves the underlying library fundamentally, not accidentally, simpler. This can get you into some trouble in some cases, for instance XML is a better choice for HTML-type tagged text as the JSON for tagged-text is just hideous (and, interestingly, reopens the dimensionality problem as there is no one obvious solution), but many things are fundamentally simpler than tagged-text.

If you want to pick up a defined serialization format, my gut would be to say to default to JSON and back to XML if you really need it for something... but be aware that you may, and it's no better to try to jam JSON on top of a fundamentally XML problem. (Besides, your JSON can carry bits of XML in it without much pain, so "best of both worlds" is perfectly feasible.)

Re:Why is JSON so popular? Developers want out of the syntax... by tptacek on Friday March 19, 2010 @11:13AM (#1204292)
Whoah wait hold on a sec. I'm not sticking up for XML. I'm just saying that one argument isn't valid. I'd use JSON.

(Although I like it when my target web apps use XML; better tools support for attacking them.)

Re:Why is JSON so popular? Developers want out of the syntax... by jerf on Friday March 19, 2010 @11:23AM (#1204314)
Righty-o, like I said I wasn't sure. :) But I figured it was still worth posting. I don't see much level-headed analysis of the issues. Too many devs got burned by XML then can't help but get a little fanboy-ish over JSON, which has distorted the dialog a bit, I think. And I like getting the idea of API dimensionality out there.
Re:Why is JSON so popular? Developers want out of the syntax... by binspace on Friday March 19, 2010 @02:23PM (#1204845)
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... by jerf on Saturday March 20, 2010 @09:56PM (#1207382)
Actually, it's really easy to write, if you want to. I haven't had any need in my big JSON project (everything ends up pretty hierarchial so any query like "give me all the object attributes that are 'xyz'" isn't useful), but if I needed one it would be easy to write. A good learning exercise for recursion, if you're not familiar with it.