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
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









