Thursday, October 9, 2014

JSON vs XML

Introduction:

First off, definitions for those unfamiliar with JSON and XML.  JSON stands for JavaScript Object Notation.  XML stands for eXtensible Markup Language.  Both are used for data interchange that's somewhat easy to read that contain data-value pairs for server and web applications.

Pros and Cons:

JSON is not quite human friendly but the data is stored in arrays so that has its advantages.  JSON is more compact in terms of data transport as well as differentiating between data types (i.e.: 1 and "1").  JSON is also easily consumed by javascript as well as representing a null value.  JSON doesn't require ending tags for each tag (less characters = faster internet transport) but it's a bit more difficult to determine attribute versus values.

XML is more human reader friendly but requires ending tags for each tag generated.  XML data is stored in trees versus using arrays like JSON.  XML has wider support than JSON in terms of languages and frameworks.  It also can adhere to a very specific declared schema which when it validates correctly you can start parsing data.  XML is older than JSON so it has more of a reach in the coding community than JSON.

Onto some coding samples:

Yep I'm still a fan of RPGs :).  Here is a sample of JSON and XML for a generic Shadowrun type character, just the basics but enough to get the gist of coding differences.

JSON:


XML:

Addendum:

Why yes I did put in some funky characters into the sample (double quotes).  JSON does account for special characters in a very similar manner you use with C# string manipulation.  A semi-comprehensive list of special characters and how to deal with them for JSON can be found here.

Source:

http://stackoverflow.com/questions/5615352/xml-and-json-advantages-and-disadvantages
http://www.programmableweb.com/news/xml-vs.-json-primer/how-to/2013/11/07

No comments:

Post a Comment