Reputation: 77
Several of my webpages names contain the following character &
, for example "Shipping & Deliveries", etc.
My Schema markup is injected with GTM (JSON-LD) but in SDTT I get the following error:
Uncategorized Errors: 1 ERROR
JSON-LD: Bad escape sequence in string.
I have set up a variable in GTM, "CSS Selector" targeting "H1", which in the above example retrieves the page title "Features & Options".
But in SDTT, the code shows up as follow when testing through URL fetching:
"name": "TOPIC TAG: FEATURES \x26 OPTIONS"
Any idea how to properly escape the sequence?
Upvotes: 3
Views: 5015
Reputation: 422
It's more like a workaround than an answer, as it doesn't convert these characters, but when I had the same problem I just use replace in the custom variable i use in the JSON-LD microdata. Do - for your case - instead of using DOM variable - create Custom JavaScript Variable:
function() {
var h1 = document.querySelector('h1').innerText;
var cleanh1 = h1.replace(/&/g, "and");
return cleanh1;
}
That way your JSON-LD will work like a charm.
If there is a chance that in the H1 the innerText returns &
instead of just &
- you can add it in the replace:
var cleanh1 = h1.replace(/(&|&)/g, "and");
Hope this help.
Upvotes: 1