liveBook · Manning

Serialization

As explained in Data-Oriented Programming: Reduce software complexity

Serialization is the conversion of structured data into a representation suitable for storage or transmission.

Serialization converts structured data into a representation suitable for storage or transmission. JSON serialization turns fields and values into a string; deserialization reconstructs data from that representation. section 1.2.3 section 6.3

A deceptively simple task becomes awkward when data is locked inside object-oriented classes. Each new JSON shape can require another class and repeated serialization and deserialization code, whereas data-oriented designs provide more generic access to data. section 1.2.3 section 1.3

Practical rules make serialized data easier to use:

  • Serialize structured values with JSON.stringify before writing them to disk. section 15.4
  • Deserialize stored or returned JSON with JSON.parse before comparing or processing its data. section 6.3
  • Avoid comparing JSON strings directly: different field orders can serialize the same data. section 6.3
  • Pretty-print JSON with an indentation argument when people need to inspect captured data. section 15.4

Testing a JSON search result

A search function can return JSON.stringify(results). A test should apply JSON.parse to that result and compare the resulting data with [bookInfo] for a matching query or [] for a nonmatching query. section 6.3

Listing 6.12 The code of Library.searchBooksByTitleJSON
Library.searchBooksByTitleJSON = function (libraryData, query) {
  var catalogData = _.get(libraryData, "catalog");
  var results = Catalog.searchBooksByTitle(catalogData, query);
  var resultsJSON = JSON.stringify(results);
  return resultsJSON;
};

Inspect a complete JSON-producing search function and trace how its result is tested after deserialization. section 6.3

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Explains conversion, generic-access trade-offs, readable output, and test comparison, but stops short of serialization internals.
Examples
Demonstrates search endpoint payloads, captured catalog context, JSON file formatting, and deserialized search-result assertions.
What it assumes
Assumes basic structured data and unit-test familiarity while teaching JSON serialization and deserialization through search examples.
What you can do after
Apply it via JavaScript JSON.stringify and JSON.parse to store, inspect, reload, and test structured data.
How it connects
Connects JSON, deserialization, unit testing, object-oriented programming, data-oriented programming, and data immutability.

Also explained in

Compare how 24 books explain serialization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.