Readit News logoReadit News
jtchang · 15 years ago
Thank god. I hate XML.

XML has its uses but honestly when it comes down to it working with JSON is a lot easier. When picking a data interchange format you need to consider indirect advantages as well. JSON is easier to read on a screen, type out, and overall skim. Skimming XML is a pain.

guelo · 15 years ago
I disagree on readability, a big chunk of deeply nested JSON is not easy to read at all. Most smart XML viewers, including most browsers, have folding and coloring which make it pretty easy to read.
smallegan · 15 years ago
I agree about the smart xml viewers and the fact that most browsers support the friendly treeview's etc... However shouldn't browsers just as easily be able to do the same with JSON? And I believe most JSON viewers I've seen give you the same type of presentation of objects and lists...
thibaut_barrere · 15 years ago
The only thing I miss from XML is the ability to comment out something. I discovered the other day that it wasn't apparently possible.
axod · 15 years ago
If you don't care about the standard, you can use / * * / to comment out stuff in JSON. It's a shame this wasn't in the spec. Along with making quotes optional for keys.

It's a real shame that the native JSON object, and the spec missed out these useful features...

   var obj = eval("({foo:3 /*,bar:7*/ })");
Works fine, but JSON.parse and probably most other JSON libs throw a hissy fit for no good reason.

I love JSON, but making quotes compulsory for keys, and missing out comments are both a PITA.

davepeck · 15 years ago
Formats targeted strictly at machine/machine interchange ultimately get used for much more. JSON is no exception.

Configuration tends to be the first place that interchange formats are "abused"; even for such a mild abuse, comments are essential. (Hard-core abuses, like XML-based programming languages, are another thing entirely. :-)

To deal with JSON's lack of comments, I've considered writing services and apps that produce JSON, but consume YAML. Here, the interesting qualities of YAML are (1) it's a superset of JSON, and (2) it supports comments.

Deleted Comment

viraptor · 15 years ago
I'm quite surprised. What did you need the comments for?
tomjen3 · 15 years ago
Depends on your language - in Scala XML is so much easier than JSON, mostly because Scala allows you to do pattern-matching and do functional programming on Xml.

But if you are working in Javascript, then yeah it is properly easier.

andreyf · 15 years ago
A little rude, isn't that? There's different fundamental metaphors: XML is a way of representing a tree with labeled nodes, and also a markup format; JSON is the representation of arrays, simple maps, and basic types in unicode. Each has its uses.
RyanMcGreal · 15 years ago
Their uses overlap in that they both broadly serve as a language for defining structured data being transfered between two different systems. For most use cases in this space, JSON is a) expressive enough and b) far easier to render, read and parse.
joe_the_user · 15 years ago
Whatever the merits of the two methods, making the API a moving target really sucks for anyone might, say, be in the middle of writing to it.
jhrobert · 15 years ago
Impedance mismatch between XML and JavaScript is killing XML.

What's next? HTML? {"head":{"title": "JOHN"},"body:"{"div": "Javascript Object Hypertext Notation"}}

bluedevil2k · 15 years ago
Hooray! Let's hope other websites follow their lead and ditch the huge SOAP/XML overhead and stick with the ease and simplicity of REST/JSON.
buro9 · 15 years ago
At Yell we're currently working on our first public API, and only on Friday did we have the conversation and decided that doing JSON well was far more important than supporting XML at all.

The decision was a quick one, we just asked the iPhone, Android and web devs where we should focus, what they wanted most. The answer was unanimously JSON.

guelo · 15 years ago
Twitter's XML API does not use SOAP.
cloudwalking · 15 years ago
Other than smaller bandwidth on each call, what advantages does JSON provide over XML?
kennu · 15 years ago
Direct mapping to most (dynamic) programming languages' datatypes, such as arrays, dictionaries, numbers and strings.

Once you get used to working with a combination like JSON and Python, you really don't want to go back to the complexity and inconvenience of parsing and generating XML.

d0m · 15 years ago
But still, deprecating XML means lots of already functional apps won't work anymore. Maybe a "All new app registered after X date will only be able to use JSON formatted data" would be better.
RodgerTheGreat · 15 years ago
XML is actually very hairy and complicated. Consider entity encoding, whitespace (as in xml:space="preserve"), and namespaces. In contrast, the complete syntax of JSON is given in 5 simple flowcharts: http://json.org/

Nearly any competent programmer could hand-roll a tested, production-ready JSON parser in under a week. Try doing the same with XML. In practice there are plenty of JSON parsers out there to choose from, but being able to completely wrap your head around something is useful.

dkarl · 15 years ago
I upvoted your comment for the info, but I have no idea why this is an advantage for anyone except the handful of people who create an implementation. Hand-rolling an XML parser is a pretty sure sign of a certain kind of incompetence. Wouldn't the same be true of hand-rolling a JSON parser, unless you're one of the (rare) first guys to solve the problem for your language or language platform? To put it another way, wouldn't this only have been an advantage before XML libraries became commonplace? The last time I reached for an XML library and found there was none already installed with my platform, I was using Tcl (and it wasn't hard to find TclXML.)
zdw · 15 years ago
Benefits JSON > XML: Less bandwidth for same data, Quick to load, quick to parse. Very web friendly.

Benefits of XML > JSON: Easy to validate structure and content (via schemas), and transform content in a language neutral manner (via xslt). Older, thus supported in more places.

Use what works - JSON is fine for web stuff, XML is better for things that need strict validation and/or long term data storage.

brunoc · 15 years ago
Regarding schemas - there is JSON Schema:

http://json-schema.org/

http://tools.ietf.org/html/draft-zyp-json-schema-02

We've been using this pretty extensively at work. The Java guys wrote something to generate their model from it and on the JavaScript side we've used it to do all kinds of nice things like automagically generating forms that validate according to the schema and verifying that the data we receive from the backend conforms to it in our tests.

From what I can gather very few people are using it. It's not exactly fun to write but a co-worker of mine wrote a dsl to make that less painful.

Of course when you write JavaScript, it's a joy to work with.

On the transformation side there are a few ideas floating, notably JSON-T

http://goessner.net/articles/jsont/

Neither of these things are as mature as XSD and XSLT, but if you love JSON and JavaScript, they're definitely worth investigating.

andrewvc · 15 years ago
I never really got the 'why' behind XML Schemas. Why would you validate a document with a schema vs actual code? It's just a bigger pain in the ass, and more limited.

Deleted Comment

simonw · 15 years ago
Here's a piece I wrote about JSON v.s. XML back in 2006: http://simonwillison.net/2006/Dec/20/json/
runT1ME · 15 years ago
Sigh

I just implemented my project's API in XML. Time to switch I guess...

polynomial · 15 years ago
Since the 1st line of the article indicates this is the streaming API only, I will presume that's the one your project is written against.
Jach · 15 years ago
On XML vs. JSON, I used to hate XML until I started programming in ActionScript which has a really nice syntax for it (except a few oddities here and there). I use Enunciate at work ( http://enunciate.codehaus.org/ ) which generates XML, JSON, AMF, SOAP/REST endpoints all by itself from base Java services and classes, which works well too.

Can't say I'm disappointed, back when I did twitter dev I used JSON for everything, plus it was really easy to interface with our JavaScript client (duh).

tomjen3 · 15 years ago
I haven't used Action script but Scala has really nice support for Xml - it is properly the only language that allows you to do pattern matching on XML.
simonw · 15 years ago
Scala's creator is on record as regretting the inclusion of XML literals in the syntax of the language:

http://www.codecommit.com/blog/scala/working-with-scalas-xml...

jluxenberg · 15 years ago
The article on Programmable Web doesn't add any value to the original press release: http://groups.google.com/group/twitter-development-talk/brow...
asnyder · 15 years ago
You'll likely still be able to get results in XML via YQL which offers their own XML or JSON outputs for most web services.
simonw · 15 years ago
YQL won't work for Twitter's streaming API - it's designed for standard request/response style APIs.