AdvertServe Cloud Ad Server Solution

API: JSON vs XML

API: JSON vs XML

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. Based on a subset of the JavaScript Programming Language, JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

JSON vs XML

You might already be using our API with XML so why might you want to switch to JSON? In most cases there really is no reason to switch aside from personal preferences. Many people find XML very verbose and clumsy to work with while JSON is very compact and easier to read and write. If you are more comfortable and productive with XML, then you should use XML. Otherwise you can choose to use JSON instead if you feel like it is a better fit for you.

Comparison

So, you might be wondering, just how much more compact and readable is JSON compared to XML? Here's an example of the data returned when retrieving the information for a zone in both JSON and XML.

JSON

{
  "id": 1,
  "name": "Top of Page / 728x90",
  "group": 2,
  "type": 1,
  "size": 19,
  "targeting": [
    4,
    8
  ],
  "status": true,
  "recycle": false,
  "notes": "",
  "campaigns": [
    {
      "id": 3,
      "default": false,
      "chain": 0,
      "priority": 1,
      "status": true
    },
    {
      "id": 4,
      "default": false,
      "chain": 0,
      "priority": 1,
      "status": true
    }
  ],
  "publishers": [
    1,
    2
  ]
}

XML

<zone id="1" name="Top of Page / 728x90" group="2" type="1" size="19" targeting="000010001" status="true" recycle="false">
  <notes/>
  <campaigns>
    <campaign id="3" default="false" chain="0" priority="1" status="true"/>
    <campaign id="4" default="false" chain="0" priority="1" status="true"/>
  </campaigns>
  <publishers>
    <publisher id="1"/>
    <publisher id="2"/>
  </publishers>
</zone>

As you can see the JSON is actually slightly larger than the JSON in this case. This is not typical, however, it is pretty clear that the JSON is much easier to read and understand. Why does that matter? You are writing programs to read the JSON right? Well, if you find yourself tracing HTTP requests to view the data going back and forth between the API, trust me, I can tell you that JSON is much easier on the eyes! It is also much nicer for those folks that like to dig and explore the API without reading the documentation :)

The Verdict

Having the option to choose between using JSON and XML is a good thing. It gives you the flexibility to pick the right tool for the job. Interested in learning more about JSON? Head on over the official JSON web site at http://www.json.org/

← AdvertPro Version 2.5
Share of Voice Reports →