The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

294119 (38) [Avatar] Offline
#1
rawJSON :: BC.ByteString
rawJSON = "{\"author\":\"Emil Ciroan\",\"title\":\"A Short History of Decay\",\"year=1949}"

There are actually two JSON format errors:
1) The = should be replaced by :. This error was identified earlier in one of the Errata/Typo listings
2) The JSON key year has an opening quote but no closing quote.

I believe the correct declaration should be:
rawJSON = "{\"author\":\"Emil Ciroan\",\"title\":\"A Short History of Decay\",\"year\":1949}"


On page 514, I believe the author wanted to set up the case where a key was missing:
wrongJSON :: BC.ByteString
wrongJSON = "{\"writer\":\"Emil Ciroan\",\"title\":\"A Short History of Decay\",\"year=1949}"

This has the same additional errors with the year.
The correction recommended earlier in the Errata/Typos fixes : for = but omits the fix for the missing closing quote for year.

I believe the correct declaration should be:
wrongJSON = "{\"writer\":\"Emil Ciroan\",\"title\":\"A Short History of Decay\",\"year\":1949}"

If the year portion is not completely fixed, then
GHCi> eitherDecode wrongJSON :: Either String Book will return

"Error in $: not enough input"

instead of the expected

"Error in $: key \"author\" not present"