Search code examples
jsongoogle-mapsgoogle-maps-api-3json-deserialization

google map JSON.parse: bad escaped character at line 1 column 42 of the JSON data


I have string which was stringified from google map object.

the string: [{"type":"polygon","path":"kryA}iejSZYJ\I^"}]

When trying to parse this string back to object using JSON.parse, I've got the error

SyntaxError: JSON.parse: bad escaped character at line 1 column 42 of the JSON data

my code was

JSON.parse('[{"type":"polygon","path":"kryA}iejSZYJ\\I^"}]')

So what is wrong here? Did google produce a bad code that when stringified, it can not go back to object again?


Solution

  • i think you are not properly encoding json. BTW if you try like this

     var obj =  [{"type":"polygon","path":"kry`A}iejSZYJ\\I^"}] 
    

    then it will work