JSON Schema compared with XML Schema and their future

Alain picture Alain · Mar 24, 2012 · Viewed 16.6k times · Source

I was looking for JSON schema standards and their corresponding php implementations. Expecting some open source out there and I was surprised, to find only one php implementation. I was about using this technology (JSON) and the schema lib to parse my incoming browser requests.

This natural parse/validate activity seems natural in XML and make me wonder why this is not the case in JSON.

I end up with a doubt situation. Should I pursue my JSON structure data exchange or switch to XML? I first chose JSON for its simplicity and less verbose syntax compared to XML, but if I have to redevelop all existing standard in the world these arguments becomes lighter. I also chose JSON hoping to limit the size of communications between my web server and my mobile apps. Playing with comet apps, XMPP seems to be implemented and used by big names like Google, Facebook, for their real time chat chat text or video based messages.

So the actual questions are:

  1. Is JSON for the poor web server developer that wants to know what happen on its traffic, and focus on over simplicity (do not be mistaken, here, I include myself)?
  2. Does IETF draft for JSON schema is a serious work, since only few implementation exist on the server side (PHP)?
  3. Am I missing something, or maybe, the best communication pattern is to send data in xml to the server and expect a json response (many json schema implementation exist in javascript)?
  4. Or did I only faced the actual proof, that this concern has not been well served by the developer community because web developer using JSON do not test deeply their incoming request data?

Please help me understand, I am missing some experience here?

Answer

Bogdan picture Bogdan · Mar 25, 2012

This natural parse/validate activity seems natural in XML and make me wonder why this is not the case in JSON.

Remember what made JSON famous: web applications with a very rich user interface written in JavaScript. JSON was perfect for that because data from the server mapped directly on JavaScript objects; hit a GET URL with Ajax and get back an object, no need for parsing or anything else.

Those rich interfaces made JavaScript a very popular language and JSON obviously rode along and it's popularity made it become the best candidate to overthrow "the angle bracket".

But XML has a long history behind it. It's a mature technology with lots of accompanying specifications. JSON is just catching up to those.

Although the draft specification expired in May 2011, the JSON Schema supporters think they have reached a pretty close to final version of the spec. So who knows what the future has in hold for JSON Schema.

I was surprised, to find only one php implementation [...] Does IETF draft for JSON schema is a serious work, since only few implementation exist on the server side (PHP) ?

Does this PHP implementation validate JSON as per the last version of the JSON Schema draft? If yes, is there a need for other implementations? Do you need lots of implementations to certify a specification is serious? That's just as saying that XSLT 2.0 is not serious because Microsoft didn't bother to implement it.

As for your last question, incoming data needs to be validated. You don't take a user request and throw it to the server and "hope it sticks". You validate it; and JSON Schema is not the only way to validate JSON data, so don't assume that web developers using JSON do not deeply test their incoming request data.

In conclusion, what I'm trying to say is that JSON can't fully replace XML, or the other way around. So use each technology where appropriate.