Twitter Goes JSON-Only With One API
blog.programmableweb.com
blog.programmableweb.com
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.
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.
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.
Because of the lack of comments I copied the old version to a new file etc.
But if you are working in Javascript, then yeah it is properly easier.
What's next? HTML? {"head":{"title": "JOHN"},"body:"{"div": "Javascript Object Hypertext Notation"}}
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.
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.
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.
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.
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.
If that code becomes worthy of public release, I'd bet it could dramatically raise the profile of JSON Schema.
I guess I haven't really worked in a heterogenous environment with a lot of XML before though, I can see the potential value there, but i'm still doubtful.
For example, if you have an RelaxNG schema (which has a great compact syntax) that says that an element has to have at least one child node and that child node contains an integer between a certain set of values. Once you have that schema, you could write code that could read in the XML file and validate it against the schema in 2 lines, then grab all the child node integers with one XPath expression.
The data might be junk (heck, I'm not aware of any format that is impervious to worthless data), but at least it's junk in the right format, and you never had to mess around with parsing the input.
Need to switch programming environments or languages because you're working on Unix/Windows/embedded system/mainframe/database/web browser ? The schema can move with you (or be converted to another schema format that does), and programming niceties SAX and XPath will often carry over too.
Thanks for the careful response!
I would not be surprised if embedding a javascript interpreter and running a validation script was probably already easier in most languages than embedding an XML parser & validator.
JavaScript has become the lingua franca of programming. I hope they teach that in schools. http://en.wikipedia.org/wiki/Lingua_franca
From one point of view, JavaScript is the "Worse is Better" version of Lisp. Guess who's winning?
Ditto XML vs JSON
I just implemented my project's API in XML. Time to switch I guess...
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).
http://www.codecommit.com/blog/scala/working-with-scalas-xml...