Parsing to json when it includes an & (ampersand)

Parsing to json when it includes an & (ampersand)

Shopify Partner
2 0 1

Good night,


How should I parse to json a including an "&"? Right now, for a store titled  "Test & Store", the code {{ | json }} returns something like "Test \u0026amp; Store".


This is causing problems with Google indexation.


One solution would be using "and" instead of "&", but I am afraid it could cause SEO problems. Another solution, is using the store name hardcoded instead of the code " | json", but if in the future there is change in the shop name, it will need to be searched and updated.


Any advice?


Thanks in advance,

Reply 1 (1)

Shopify Partner
15 0 2

For anyone else that lands here - I came across the same issue when parsing products titles for inclusion in a dataLayer for GTM.  Got around it by replacing the parsed ampersand with just the html code;


{{ line_item.product.title | json | replace: "\u0026amp;", "\u0026" }}

So in your instance, maybe try:


{{ | json | replace: "\u0026amp;", "\u0026" }}