7 Basic data validation

 

A solemn gift

Hidden listing
function KlipseLoadLib(url, symbol) {
  if (window[symbol]) {
    return;
  }
  var script = document.createElement('script');
  script.src = url;
  document.body.append(script);
}
KlipseLoadLib("https://cdnjs.cloudflare.com/ajax/libs/ajv/6.12.6/ajv.bundle.js", "Ajv");

This chapter covers

  • The importance of validating data at system boundaries
  • Validating data using the JSON Schema language
  • Integrating data validation into an existing code base
  • Getting detailed information about data validation failures

At first glance, it may seem that embracing DOP means accessing data without validating it and engaging in wishful thinking, where data is always valid. In fact, data validation is not only possible but recommended when we follow data-oriented principles.

This chapter illustrates how to validate data when data is represented with generic data structures. It focuses on data validation occurring at the boundaries of the system, while in part 3, we will deal with validating data as it flows through the system. This chapter is a deep dive into the fourth principle of DOP.

Principle #4

Separate data schema from data representation.

7.1 Data validation in DOP

Theo has rescheduled his meetings. With such an imposing deadline, he’s still not sure if he’s made a big mistake giving DOP a second chance.

►Note

The reason why Theo rescheduled his meetings is explained in the opener for part 2. Take a moment to read the opener if you missed it.

7.2 JSON Schema in a nutshell

7.3 Schema flexibility and strictness

7.4 Schema composition

7.5 Details about data validation failures

Summary