Explaining JSON/YAML

Objectives

After completing this lesson, you will be able to:

  • Describe JSON and YAML

JSON and YAML

Business scenario

You find yourself needing to create configuration files for various cloud-native services. Should you use JSON or YAML? This lesson will guide you through the specifics of each, helping you make an informed decision.

What are JSON and YAML?

JSON Overview

JSON (JavaScript Object Notation) is an open-standard format for data storage and exchange. It employs easy-to-read text to encapsulate data objects, which consist of key-value pairs and arrays. Frequently utilized for web applications to communicate with servers, JSON serves as a versatile data interchange medium.

Though influenced by JavaScript's syntax, JSON operates independently and enjoys support across various programming languages. Files using this format typically have a .json extension.

JSON is fundamentally built upon two key structures:

  • A set of key-value pairs: This is often implemented as an 'object' in multiple programming languages.
  • A sequentially ordered series of values: Most languages interpret this as an 'array'.

The following figure, JSON Representation Describing a Business Partner, shows a possible JSON representation describing a Business Partner.

JSON Example

YAML Overview

YAML is a human-friendly, cross language, Unicode-based data serialization language designed around the common native data types of agile programming languages. It is broadly useful for programming needs ranging from configuration files to internet messaging to object persistence to data auditing. YAML was specifically created to work well for common use cases such as the following: configuration files, log files, interprocess messaging, cross-language data sharing, object persistence, and debugging of complex data structures. When data is easy to view and understand, programming becomes a simpler task. YAML filenames use the extension .yaml or .yml.

YAML is a strict JSON superset and includes additional features such as the notion of tagging data types, support for non-hierarchical data structures, the option to structure data with indentation, and multiple forms of scalar data quoting. YAML is an open format.

The following figure, YAML Representation Describing a Business Partner, shows a possible YAML representation describing a Business Partner.

YAML in Relation to JSON

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. Therefore, 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. Therefore, 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.

YAML can therefore be viewed as a natural superset of JSON, offering improved human readability and a more complete information model. This is also the case in practice; every JSON file is also a valid YAML file. This makes it easy to migrate from JSON to YAML if or when the additional features are required.

Summary

You now have a more profound understanding of JSON and YAML.

Log in to track your progress & complete quizzes