Wednesday, November 17, 2010

JSON vs XML, structured vs semi-structured data

That debate has been going for years now... When should you use JSON vs XML?

Interesting blog posts on this today from Norm Walsh and Noah Mendelsohn.

Both agree that:
"XML wasn't designed to solve the problem of transmitting structured bundles of atomic values. XML was designed to solve the problem of unstructured data. In a word or two: mixed content."

Noah then adds:
"If you want to send along a list of job applicants and their recent salaries, JSON does fine;  if you want to send their resumes, well JSON isn’t quite as helpful.   A surprising amount of the world’s important information is in just such semi-structured documents.  Think insurance policies, shop manuals, and even Web pages themselves."

+1 to that! I've worked -- and struggled sometimes :) -- with XML for years, and more recently with JSON, and couldn't agree more!

Adding my 2c:
When you work with structured business data, use an object (or struct, or record) model in your favorite programming language, and an object serialization encoding like JSON.

When you work with semi-structured document resources, use a document API or a document centric programming language (like XQuery, XSLT) or even better, a document-node centric programming language (like XLinq), and an XML document encoding.

You'll need both programming approaches. Don't use a single approach for everything, unless you're looking for trouble.

When you need to communicate both structured and semi-structured data, don't bundle them. Just link these resources using URI references.

Simple enough?

No comments:

The postings on this site are my own and don’t necessarily represent positions, strategies or opinions of my employer IBM.