When a function returns JSON text, comparing raw strings is a trap: two strings can serialize the same data in different property orders. Parse the text first, then test the resulting data. section 6.3
JSON.parse deserializes a JSON string into a JavaScript data structure, commonly a map. That turns an encoded response back into data that tests and application code can inspect. section 6.3 section 11.3
Testing a JSON-returning function
Parse Library.searchBooksByTitleJSON's result and compare it with the expected array using _.isEqual. A search for "Watchmen" should produce bookInfo; a search for "Batman" should produce [].
Reading a parsed request
var myString = "{\"publicationYear\":1987,\"title\":\"Watchmen\"}"; var myData = JSON.parse(myString); _.get(myData, "title"); // "Watchmen"
Listing 11.2 Parsing a JSON string in JavaScript
var jsonString =
'{"title":"habit","fields":["title","weight","number_of_pages"]}';
JSON.parse(jsonString);
Inspect a minimal JavaScript request-parsing example before comparing the equivalent Java Gson call. section 11.3
