Data serialization means translating data into a standardized format which can be stored and/or transmitted over a network and reconstructed later, often by an application different to the one that first generated the data. Serializing data allows us to transfer data between applications in a way that both will be able to understand.

Data serialization languages allow us to store data as variables which are represented with text (a name).

There are countless formats for standardizing data, but we’ll look at these:

CCNA Exam Note

Only JSON is mentioned in the CCNA Exam Topics, but XML and YAML are common enough that they’re probably worth learning about too.

JSON

JSON (JavaScript Object Notation) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects. JSON was standardized in RFC 8259. It may be worth your time to read through the RFC, as it is an authoritative source on JSON syntax & usage.

JSON was derived from JavaScript, but can be used by any programming language for formatting data, and most popular languages will have built-in features or available libraries for generating and reading JSON files.

REST APIs often use JSON, which is one reason it’s important to know for networking professionals.

Some rules about JSON syntax:

  • Whitespace (tabs, empty lines, & extra spaces) are insignificant. The file will be parsed correctly even if you add extra empty lines for readability or on accident.
  • JSON can represent four ‘primitive’ data types:
    • string
      • A ‘string’ of text. Pretty much anything you can type, you can store as a string.
      • Strings are contained in double quotes. Anything (even numbers) are strings if they are contained by double-quotes.
      • Ex.: "Hello", "five", "5", "null"
    • number
      • A numeric value. Must not be surrounded by quotes.
      • Ex.: 5, 100, 65535
    • boolean
      • Only two possible values: true or false. Not surrounded by quotes.
      • These are sort of equivalent to a single binary bit: either 1 or 0.
    • null
      • Nothing — ‘this field intentionally left blank’
      • Simply written null; no quotes.
  • JSON also has two ‘structured’ data types:
    • object
      • The term ‘object’ can mean a few different things depending on the language/context.
      • JSON objects are unordered lists of key-value pairs.
        • The key is a string; it serves as the name for its associated value.
        • The value is any valid JSON data type (string, number, boolean, null, object, array)
      • Objects are sometimes called dictionaries.
      • Objects are surrounded by curly brackets ({})
      • The key and the value are separated by a colon (:).
      • If there are multiple pairs in the object, they are separated by a comma (,).
      • Transclude of #json-object-example
    • array
      • An array is a series of values separated by commas.
      • The values do NOT have to be the same data type.
      • Arrays have a string for a name and are surrounded with square brackets ([])
      • Transclude of #json-array-example

XML

XML (Extensible Markup Language) was originally developed as a markup language1, but now it’s used as a general data serialization language.

Like JSON, XML is often used by REST APIs.

XML is considered a bit less human-readable than JSON, but it’s still pretty easy to read.

Syntax/rules:

  • Whitespace is insignificant.
  • XML is generally formatted using key tags which encapsulate data.
    • Tags are surrounded by angle brackets (<>) and every tag that is opened (used) must be closed with a ’/’ tag.
    • E.g. <Interface>GigabitEthernet0/1</Interface>

YAML

YAML was originally the acronym for Yet Another Markup Language, but to distinguish its purpose as a data-serialization language, rather than markup, it was changed to YAML Ain’t Markup Language. Yes, the ‘Y’ in YAML stands for YAML.

YAML is used by a large number of applications, notably Configuration Management Tools.

YAML is fairly human readable, though some consider it more difficult to work with.

Syntax & Noteworthy rules:

  • Whitespace is significant.
    • Unlike many data serialization languages, indentation is very important. Minor errors can make a file unparsable.
  • YAML files start with ‘---'
  • '-’ is used to indicate a list.
  • Keys and values are represented as key:value

Examples

JSON Object Example
{
	"interface": "FastEthernet0/1",
	"is_up": true,
	"ipaddress": "172.16.0.10",
	"netmask": "255.255.0.0"
}
JSON Array Example
"interfaces": [
	"FastEthernet0/1",
	"FastEthernet0/2",
	"FastEthernet0/3"
]

Footnotes

  1. A computer language used to format text. HTML, the basic language that all websites are written in is a markup language. Fun fact, the repository that this website is (almost) entirely written in Markdown, which is also a markup language (with a tongue-in-cheek name).