Live data from Hacker News

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

stereolambda.wordpress.com

41–50 of 120 posts

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

#41
post #7

Well JSON also lets you get around browsers' same-domain policy without having to set up a proxy, which I think might be more important.

if you are talking about JSONp: JSON is by no means required to do that. You could in theory easily pass a string containing XML to the callback function.

Yes, good point.

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

#42
post #32
post #29

Earlier quoted context omitted.

Yeah, but the downside to doing that with XML is it's frickin crazy. I have to parse this whole thing into memory and then pull out the part I want? The CPU is spending more time dealing with XML than it is doing useful work. If it's a big file, this is very significant. In JSON, you get the same expressiveness without the hassle.

I'm not sure what you think your JSON parser is doing.

Come on. Any one of us could write a JSON parser in a page of code. An XML parser is significantly more work due to the overcomplexness of XML. Both to write, and for the CPU to run. And it's larger. In fact I'm struggling to think of something XML has that is good. (And please no one respond with "it's extensible" or I may explode).

An XML parser has to track open tag names, with JSON it doesn't matter. XML has all stupid entities like & which look ugly and need to be parsed.

I think "time to write a parser" should be a good metric on how sane a data format is. The fact that writing an XML parser that covers all bases/eventualities is a major undertaking says alot about the data format.

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

#43

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…

Please don't write "begs the question" when you mean "raises the question". http://begthequestion.info/

But if we know what he meant why does this matter? Language exists to convey meaning, and I think we all understood what he meant, so I don't see the problem here.

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

#44
post #33
post #29

Earlier quoted context omitted.

Yeah, but the downside to doing that with XML is it's frickin crazy. I have to parse this whole thing into memory and then pull out the part I want? The CPU is spending more time dealing with XML than it is doing useful work. If it's a big file, this is very significant. In JSON, you get the same expressiveness without the hassle.

I have to parse this whole thing into memory and then pull out the part I want? You do that with JSON too, don't you? Are there SAX-like parsers for JSON? If it's a big file it'll be big in JSON too.

If the file is big, chances are that it is basically a sequence of relatively small chunks. You don't need SAX parsing for this. Just read the file one chunk at a time.

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

#45

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…

Please don't write "begs the question" when you mean "raises the question". http://begthequestion.info/

Whoops. You're right. I'm embarrassed because I do know the difference.

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

#46
post #32
post #29

Earlier quoted context omitted.

Yeah, but the downside to doing that with XML is it's frickin crazy. I have to parse this whole thing into memory and then pull out the part I want? The CPU is spending more time dealing with XML than it is doing useful work. If it's a big file, this is very significant. In JSON, you get the same expressiveness without the hassle.

I'm not sure what you think your JSON parser is doing.

Well, in XML you're prone to files like (lets see how news.yc renders this):

thingy1 ...

I've seen that a billion times, if you're doing DOM, you have to pull that whole thing into memory and then run over it again. Most JSON-based storage systems I've seen recently are more record based so you can stream it through.

So I guess my beef on that one isn't specifically with XML, you could split the above snippet into separate entities.. but I'll note that it still involves about 90% markup and 10% data. Not exactly the most efficient thing possible.

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

#47
post #33
post #29

Earlier quoted context omitted.

Yeah, but the downside to doing that with XML is it's frickin crazy. I have to parse this whole thing into memory and then pull out the part I want? The CPU is spending more time dealing with XML than it is doing useful work. If it's a big file, this is very significant. In JSON, you get the same expressiveness without the hassle.

I have to parse this whole thing into memory and then pull out the part I want? You do that with JSON too, don't you? Are there SAX-like parsers for JSON? If it's a big file it'll be big in JSON too.

There are a few event-based JSON parsers; yajl is the most famous, though its interpretation of the JSON spec is a bit liberal for my tastes.

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

#48
post #25

Earlier quoted context omitted.

How? I'm evaluating strings that are built with my javascript code or from my server code, not arbitrary user input from other users. Yes the user is able to enter parenthesis into a textbox, and those become part of the evaluated string, but I regex replace out everything but the actual parenthesis.

Every security assessor's favorite answer to a threat: "but I regex out everything unsafe".

How is building an intermediate portion of a nested logical statement, using eval() dangerous?

Here is the regex for what I allow (only '[' & ']'):

  value.replace(/[^(]/g, '').replace(/\(/g, '[')
  value.replace(/[^)]/g, '').replace(/\)/g, '],')
I guess the point you all are trying to make is that some javascript text could have been maliciously inserted into the page somehow, and accidentally get eval'd simply because eval is in use, but the page below says that one of the only times eval should be used is to build up complex mathematical expressions. Is there a safe way to build up such expressions? Send it to the server, and invoke a JS engine there? The reason I made my original comment was because I found the eval function to be so helpful in this scenario, b/c I didn't need to use any type of syntax parsing.

http://blogs.msdn.com/ericlippert/archive/2003/11/01/53329.a...

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

#49
post #17

I can't really understand all the XML-bashing. Of course it isn't the right tool for any job, but I like it for its schema and validation features.

Mostly it is a reaction to the over use of XML and how and why in many situations using something other then XML is beneficial. If a large swath of people of start using JSON without thinking about you will probably start seeing a similar reaction extolling the virtues of another format over JSON.

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

#50
post #17

I can't really understand all the XML-bashing. Of course it isn't the right tool for any job, but I like it for its schema and validation features.

Yes, those are good features.

The trouble was that it was the all-purpose data exchange tool for a long time, and everyone has seen XML put to all sorts of ungodly purposes. If it were invented today, nobody would be bashing it, because it would be less widely used -- the few people who did decide to use it would be putting it to good use, so they would love it. Everyone else would be using something else that was simpler.

Post reply on HN