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 @01:06PM (#1204577)
XML brings a lot of other baggage to the party. Some of it can be useful. I particularly like XML namespaces, because when used properly there's hardly an equivalent in any other standardized serialization format I know. (And part of the problem is that you really need it standardized at the serialization format level for it to work; you can hack things into any other format but by definition you're not doing it in a standard way.)

However, that statement should be understood through the filter of the fact that I've only seen one thing that uses XML namespaces properly, and that's XHTML. Everything else I've seen gets it wrong, and that includes most things trying to deal with XHTML....

You also get a "free" and modestly powerful validation system, a serialization format that has seriously thought through encoding issues and has answer for them (JSON does too, but a lot of other fly-by-night stuff doesn't), a fairly powerful format for tagged text (JSON-tagged text is a hack no matter how you slice it). You also get XSL, which floats some people's boats, though I wouldn't be caught dead working in it.

If you don't need any of that, don't use it. I don't very often. But when you need it, do. Also:

"An XML parser has to track open tag names, with JSON it doesn't matter."

This is equivalent to JSON needing to track {, [, ', and ", among other things. That's just parsing; both JSON and XML need to be parsed. That's not an advantage.

"XML has all stupid entities like & which look ugly and need to be parsed."

This is equivalent to the escape sequences in JSON: http://json.org/string.gif They also need to be parsed, they do not magically turn into bytes without that.

Re:Why is JSON so popular? Developers want out of the syntax... by axod on Friday March 19, 2010 @01:41PM (#1204706)
>> This is equivalent to JSON needing to track {, [, ', and ", among other things. That's just parsing; both JSON and XML need to be parsed. That's not an advantage.

JSON can simply count brackets. That makes for a very simple parser indeed. XML needs to cope with invalid nesting, end tag names not matching start tag names etc. End tag names are just wasted space.

>> This is equivalent to the escape sequences in JSON: http://json.org/string.gif They also need to be parsed, they do not magically turn into bytes without that.

But those are sane. We all escape double quotes and backslashes in pretty much every programming language. They make sense in a very simple encoding.

Why should I need to replace & with %amp; they seem arbitrary, and the replacements aren't simple. " ?? seriously? you're naming characters with odd abreviations, and then expecting people to remember those? why not just escape them with a prefix such as erm.... "\"

Re:Why is JSON so popular? Developers want out of the syntax... by viraptor on Friday March 19, 2010 @05:45PM (#1205367)
> XML needs to cope with invalid nesting, end tag names not matching start tag names etc.

I think you read a different spec ;) http://www.w3.org/TR/REC-xml/#sec-logical-struct :

    Well-formedness constraint: Element Type Match

    The Name in an element's end-tag MUST match the element type in the start-tag.
XML parser rejects the document as soon as this occurs. No different than with `{]` in JSON.

Changing " into " allows you to go to the next " without worrying about the contents before. The next " is the ending quote. Then you can resolve all the internals lazily... saving on processing time compared to JSON. For example "\"\\\"" will go through many branches and conditions. ""\"" is a simple jump over to the next " character.