YAML

YAML

YAML, a recursive acronym for YAML Ain't Markup Language, is a human-readable and human-writable data interchange format for storing and transmitting the information. It is a strict superset of JSON, meaning that all valid JSON documents are equally valid YAML files.

YAML performs many of the same functions as XML or JSON. The main difference is that it aims to be concise in syntax and punctuation to facilitate being written by hand instead of being computer generated.

How is data encoded in YAML?

YAML has two top-level elements, an object (which consists of key-value pairs) and an array (which consists of an ordered set of values). Keys can only be strings, while values can be one of the following types:

  • object: a collection of key-value pairs. Each key is followed by a :
  • array: an ordered list of values, with a - preceding each item
  • string: an ordered sequence of text, optionally enclosed in ' ' or " "
  • number: a numeric value expressed in decimal, with exponent notation allowed
  • boolean: true or false
  • null is the implicit value where any value does not follow the colon
  • comments are any content in a line after # which the parser ignores

YAML can describe nested, and complex data structures since both objects and arrays can contain values that might be objects or arrays. YAML uses indentation for nesting, similar to Python.

How are the shortcomings of YAML?

YAML makes minimal use of punctuation, emphasizing more on the text content with ample whitespace. This verbosity makes YAML very hard to minify, making it unsuitable for carrying data over the wire.

Example

 
org:
  name: DeepSource
  login: deepsourcelabs
repo:
  name: good-first-issue
  activelyMaintained: true
  stats:
    - type: stars
      count: 400
    - type: forks
      count: 130

Write clean and secure code with DeepSource

Powerful static analysis that takes 5 minutes to set up and helps you fix code health and security problems on every pull request.