Data Formats

What is Serialized Data?

  • All data sent via HTTP are strings

  • Unfortunately, what we really want to pass between web applications is structured data (i.e., arrays and hashes)

  • Thus, native data structures can be serialized into a string representation of the data

    • This string can be transmitted and then parsed back into data by another web agent.
  • There are two major serialized data formats…


JSON

JSON stands for “JavaScript Object Notation” and has become a universal standard for serializing native data structures for transmission. It is light-weight, easy to read and quick to parse.

{
  "users": [{ "name": "Bob", "id": 23 }, { "name": "Tim", "id": 72 }]
}

Remember, JSON is a serialized format. While it may look like an object, it needs to be parsed so we can interact with it as a true Javascript object.

For more information about JSON


XML

XML stands for “eXtensible Markup Language” and is the granddaddy of serialized data formats (itself based on HTML). XML is fat, ugly and cumbersome to parse. It remains a major format, however, due to its legacy usage across the web. You’ll probably always favor using a JSON API, if available.

<users>
  <user id="23">
    <name><![CDATA[Bob]]></name>
  </user>
  <user id="72">
    <name><![CDATA[Tim]]></name>
  </user>
</users>

Many APIs publish data in multiple formats, for example…