JSON or XML ? Both, use json-n-xml

Both XML and JSON are widely spread data formats with both their pros and cons. That’s why I decided to write and put on GitHub json-n-xml, a library which allows switching from one format to the other (bi-directionnally). With it, you can build a DOM of a JSON and query your JSON using XPath. You can then re-serialize a DOM back to JSON. For the time being, you have use an XMLized version of the JSON format called xjson which has a very straight-forward mapping to and back to the original JSON. The future will likely provide new features..

Personnaly, I am a heavy user of XML and won’t give it up to JSON because there is one essential feature JSON doesn’t have. Indeed, people often forget that the X in XML is for eXtensible markup language. A very important notion most people just don’t talk about are namespaces which are just simply absent of common JSON usage. I also happend to love declarative programming and therefore I’m a big fan of XSLT (but I know there are not many of you out there).

That said many people out there have a preference for JSON. Whatever the reasons, the fact is that both are out there. I always find that those language or format flame-wars are just silly as they are often trying to determine which one is “better”. It’s just an endless debate since the “best” is always very relative to the context (the people, the exising habits and the task).

The solution I favor is leaving choice. And for choice to be possible you need to be able to switch from one format to the other. For example, I recently have been using ElasticSearch quite a bit, which is really good stuff. However, it uses JSON. On the other hand, I also use Apache Camel, which is an excellent enterprise service integration software. In my Camel routes, I very often use XML and Xpath for data processing. Now, to continue working this way and integrating ElasticSearch, well the format conflict got in the way.

So, please try out json-n-xml and let me known what you think !

Leave a Reply