JSON and YAML in JavaScript

This is an experiment with JSON and YAML in JavaScript.  In case you haven’t heard of either, here’s a description of both from their web sites.

From http://www.json.org/

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.  JSON is built on two structures:

  • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

From http://www.yaml.org/

YAML: YAML Ain't Markup Language

What It Is: YAML is a human friendly data serialization
  standard for all programming languages.

The relationship between the two languages is described in section 1.3 of http://www.yaml.org/spec/1.2/spec.html.

Both JSON and YAML aim to be human readable data interchange formats. However, JSON and YAML have different priorities. JSON’s foremost design goal is simplicity and universality. Thus, JSON is trivial to generate and parse, at the cost of reduced human readability. It also uses a lowest common denominator information model, ensuring any JSON data can be easily processed by every modern programming environment.

In contrast, YAML’s foremost design goals are human readability and support for serializing arbitrary native data structures. Thus, YAML allows for extremely readable files, but is more complex to generate and parse. In addition, YAML ventures beyond the lowest common denominator data types, requiring more complex processing when crossing between different programming environments.

An interesting, and slightly humorous, description of JSON and its modern relevance is here:


What to use?

I’m using json2.js (because it came installed with WordPress).  You can get json2.js here:


I’m also using yaml.js from js-yaml located here: