by cloudwalking · 16y ago · 0 comments
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.
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