Error whilst JSON decoding string containing an escaped double quote


#1

I’m trying to decode a string containing an escaped double quote, e.g. “I said, “Hello””

Now to do that in Elm, I may use Json.Decode as Decode:
Decode.decodeString Decode.string "\"I said, \"Hello\"\""

However, this is causing the decoder to fail. Can anyone explain why? I’d like to know how to have double quotes in my JSON string.


#2

When you escape the quotes like that you’re ending up with:

"I said, "Hello""

And that’s not valid JSON, so you will need to escape the quotes and the backslashes:

"\"I said, \\\"Hello\\\""

#3

Thank you so much, I got what I was doing wrong!


closed #4

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.