Unparsable structured data Structured data with syntax errors detected Bad escape sequence in string
Looking at the search console’s help page for that error reveals the following information:
|Bad escape sequence in string||An invalid escape sequence used in a string value. For example: “description” : “Some \q unknown sequence”|
In my specific case, the single quote character
' in the original text was being transformed into this mess in the JSON-LD description field:
\x26rsquo. This is mixture of unicode and HTML entity. :)
\x26 is unicode for the
&rsqou is the HTML entity for the original (right) single quote
Ok, but how do I fix the error?
If you are using the hugo static site generator, like me, you first need to find the template that generates your structured data. If you don’t know where to look, try searching all your template files for
"@context" : "http://schema.org".
In one of those files you will find a line looking something like this (I have unwrapped the single for readability):
Look at line 3 and 6, using the
| plainify. This pipes the string into hugo’s plainify-function that, according to the documentation “Strips any HTML and returns the plain text version of the provided string.” For our purpose, that is not enough. Turns out, that this is not enough when you are encoding for JSON-LD. I have found that adding
htmlUnescape before using
plainify will make sure that none of this strange double-encoding happens. The end result looks like this (line 3 and 6):
If you want to test if this fixes your problem, Google provides a handy test-tool for that: Rich Results Test.