Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
{ "@type": "ListItem", "position": 2, "item": { "@id": "{{ routes.collections_url }}/{{ collection.handle }}", "name": "{{collection.title}}" } },
"name": "{{collection.title}}" in the code above is supposed to output value like "48 to 59". But because of quotes that are not getting escaped, the code is throwing an invalid Schema.org error. The output below is from a collection page on the site https://www.perfectmakeupmirrors.com/collections/led-mirrors-48-59
The erroneous JSON code from this page is below:
{"@context": "https://schema.org","@type": "BreadcrumbList","itemListElement": [{"@type": "ListItem","position": 1,"item": {"@id": "/","name": "Home"}},{"@type": "ListItem","position": 2,"item": {"@id": "/collections/led-mirrors-48-59","name": "48" to 59""}}]}
Could you please help with the code to escape quotes?
Solved! Go to the solution
This is an accepted solution.
Thank you very much, Paul. But the solutions didn't work. I'm more interested in something like "{{collection.title | json }}"
https://stackoverflow.com/questions/15637429/how-to-escape-double-quotes-in-json
To then do so with liquid,
Either use the JSON filter escape it
{{collection.title | json }}
https://shopify.dev/docs/api/liquid/filters/json
Or remove or replace the quotes, code size and formatted to have example coloring to highlight easy to misread characters ( in purple and orange).
{% liquid
double_quote = '"'
escaped_double_quote = '\"'
%}
{{collection.title | remove: double_quote }}
{{collection.title | replace: double_quote, escaped_double_quote }}
💣double_quote and escaped_double_quote variable have TWO single-quote marks with characters between them between them and NO spaces in the value. When working with quote characters it can be much saner to work with preset variables than risk making a hard to find/read typo, i.e. ''"'"'".
https://shopify.dev/docs/api/liquid/filters/remove
https://shopify.dev/docs/api/liquid/filters/replace
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
This is an accepted solution.
Thank you very much, Paul. But the solutions didn't work. I'm more interested in something like "{{collection.title | json }}"
Hi @PaulNewton Could you please answer this LIQUID related question at https://community.shopify.com/c/technical-q-a/how-to-get-inventory-of-a-product-from-all-locations-i... ?
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025