JSON is frequently found in combination with RESTful APIs
, where XML has rightly fallen into disuse. This article will examine some of the ways XML and JSON are similar and different, and will show ways of using JSON to our advantage.
Some code examples will show how to create and interpret JSON strings, and detect JSON errors.
A Bit of Test Data
Since the most important thing a programmer can have
is a good test case, let's start with some good test data. Here is the information we will use for all of our code examples. This information will represent people, giving their names and ZIP codes. While the example is truly minimalist, it's sufficient to illustrate the principles.
A Bit of Test Data Organization
firstName lastName zipCode
John Doe 20007
Mary Doe 20016
Both XML and JSON can represent the data structure. Here is how our data will be organized.
The Old School Way: XML
People (with a date attribute)
XML, or Extensible Markup Language, is a text-string data transport mechanism. It was popularized in the 1990s when SOAP