I am using readJSON
which, in case of error, yields Left err
. Sometimes this error (a string) contains quotation marks, e. g. ReferenceError: "JSON" is not defined.
I need to return this error wrapped in a JSON string, sort of like
Left err -> "{ \"error\" : \"The error is: " ++ (show err) ++ "\" }"
(the show
is needed because we are in a fail monad.)
But when err
has quotation marks like the example above, this rips the JSON apart. How to get this working?
(In PSCI, show
seems to do a good job of escaping things, e. g. show "\"foo\""
yields a fireworks of \
. But inside a function as above, not?)