liveBook · Manning

Deserialization

As explained in Data-Oriented Programming: Reduce software complexity

Deserialization is the conversion of a serialized representation back into structured data, including JSON text in the JSON-specific sense.

A service receives JSON, but its search function needs usable data. Deserialization converts the serialized string into structured data so the program can inspect fields, run logic, and compare results. section 1.2.3 section 6.3

Listing 1.3 A JSON input of the /search endpoint
{
  "searchCriteria": "author",
  "query": "albert"
}

A search endpoint accepts structured JSON containing a search criterion and query string. section 1.2.3

Deserializing a string means generating the data represented by that string. In JavaScript, JSON.parse performs the conversion; JSON.stringify performs the reverse operation. section 6.3 section 9.4.3

Deserialization earns its keep in several practical situations:

  • Compare parsed data rather than serialized strings in unit tests, because different field orders can represent the same data. section 6.3
  • Convert JSON into an Immutable.js collection in two steps: parse the string, then apply Immutable.fromJS. section 9.4.3
  • Copy nested generic data from a debugger into a REPL by serializing it, transferring the string, and deserializing it. section 15.1
  • Load captured JSON fixtures synchronously during unit tests so the test runs only after its data is available. section 15.4

Parsing a JSON value

var myString = "{\"publicationYear\":1987,\"title\":\"Watchmen\"}";\nvar myData = JSON.parse(myString);\n_.get(myData, "title");\n// → "Watchmen" section 6.3

Listing 9.18 Converting a JSON string into an immutable collection
Immutable.parseJSON = function(jsonString) {
  return Immutable.fromJS(JSON.parse(jsonString));
};

Immutable.js deserialization wraps JSON.parse with Immutable.fromJS, turning the parsed JavaScript value into an immutable collection. section 9.4.3

Deserializing captured test data

function readData(path) {\n return JSON.parse(fs.readFileSync(path));\n}\n\nvar data = readData("test-data/searchBooksByTitle.json");\nvar catalogData = data[0];\nvar query = data[1]; section 15.4

Listing 15.22 Reading data from a JSON file
function readData(path) {
  return JSON.parse(fs.readFileSync(path));
}

A small readData helper keeps file access and JSON deserialization together for repeatable tests. section 15.4

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Defines the conversion and demonstrates JSON.parse, Immutable.fromJS, debugger workflows, and fixture loading, but does not discuss parser internals.
Examples
Uses search JSON, Watchmen data, Immutable.js collections, copied nested maps, and captured catalog fixtures as teaching examples.
What you can do after
Apply it via JSON.parse to inspect JSON, compare parsed test results, restore immutable collections, and reload captured data.
How it connects
Connects deserialization with serialization, JSON, immutable data structures, unit testing, debugging, and reproducibility.

Also explained in

Compare how 10 books explain deserialization →

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.