What's your biggest current challenge? Have your say in Community Polls along the right column.

How can I fix a parsing error in schema markup code?

Solved

How can I fix a parsing error in schema markup code?

Chisty
Excursionist
18 0 5

Any help appreciated.

I am getting an error reported via Google on the following,

Parsing error: Missing ',' or '}'

This is the code. 

The code works fine for the collection page, such as collection/ring, but it is reporting the above error if the URL includes a tag such as collection/ring/gold

<script type="application/ld+json">
{
"@context":
"https://schema.org/",
"@type":
"CreativeWorkSeries",
"name":
"{{ page_title }}{% if current_tags %} &ndash; tagged "{{ current_tags | join: ', ' }}"{% endif %}{% if current_page != 1 %} &ndash; Page {{ current_page }}{% endif %}{% unless page_title contains shop.name %} &ndash; {{ shop.name }}{% endunless %}",
"aggregateRating":
{
"@type":
"AggregateRating",
"ratingValue":
"5",
"bestRating":
"5",
"ratingCount":
"2031"
}
}</script>

 

Thanks in advance for your help

 

Chris

Accepted Solution (1)
LitExtension
Shopify Partner
4879 1003 1169

This is an accepted solution.

Hi @Chisty

You can use this snippet to solve your problem:

{

  "@context": "https://schema.org/",

  "@type": "CreativeWorkSeries",

  "name": "{{ page_title }}{% if current_tags %} &ndash; tagged {{ current_tags | join: ', ' }}{% endif %}{% if current_page != 1 %} &ndash; Page {{ current_page }}{% endif %}{% unless page_title contains shop.name %} &ndash; {{ shop.name }}{% endunless %}",

  "aggregateRating": {

    "@type": "AggregateRating",

    "ratingValue": "5",

    "bestRating": "5",

    "ratingCount": "2031"

  }

}

Hope this helps! 

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify

View solution in original post

Replies 8 (8)

LitExtension
Shopify Partner
4879 1003 1169

Hi @Chisty

Your problem is caused by this snippet:

"name":

"{{ page_title }}{% if current_tags %} &ndash; tagged "{{ current_tags | join: ', ' }}"{% endif %}{% if current_page != 1 %} &ndash; Page {{ current_page }}{% endif %}{% unless page_title contains shop.name %} &ndash; {{ shop.name }}{% endunless %}",

You need re-check this snippet. 

Hope this helps! 

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
Chisty
Excursionist
18 0 5

Thank you for your reply. Yes that was my query. I am not sure what is wrong with that part of the code that is causing the google error report. It works fine unless there is a tag on the initial query.

Be_Steven
Shopify Partner
142 28 42

"name":
"{{ page_title }}{% if current_tags %} &ndash; tagged "{{ current_tags | join: ', ' }}"{% endif %}{% if current_page != 1 %} &ndash; Page {{ current_page }}{% endif %}{% unless page_title contains shop.name %} &ndash; {{ shop.name }}{% endunless %}",

When having the tag, the real string will become kind like this
"name": "Page title here - tagged "tag1,tag2,tag3" - more content here"

As you can see there are double quote "" inside another quote "", which make the error I think.

You should try to print/log that string to check what is the real value you passed in.

Was my reply helpful? Please Like and ✔️ Accept Solution. This mean alot to me.
I'm looking for a remote job. Please contact me via besteven0912@gmail.com
Chisty
Excursionist
18 0 5

I have tried altering the code but can't get it to work on this query.

Is this what you meant?

 

"name":
"{{ page_title }}{% if current_tags %} &ndash; tagged {{ current_tags | join: ', ' }}{% endif %}{% if current_page != 1 %} &ndash; Page {{ current_page }}{% endif %}{% unless page_title contains shop.name %} &ndash; {{ shop.name }}{% endunless %}",

Be_Steven
Shopify Partner
142 28 42

The tags should still be in the quote but not the double quote because it will conflict with the parent quote

You can try this

 

"name":
"{{ page_title }}{% if current_tags %} &ndash; tagged '{{ current_tags | join: ', ' }}'{% endif %}{% if current_page != 1 %} &ndash; Page {{ current_page }}{% endif %}{% unless page_title contains shop.name %} &ndash; {{ shop.name }}{% endunless %}",

Was my reply helpful? Please Like and ✔️ Accept Solution. This mean alot to me.
I'm looking for a remote job. Please contact me via besteven0912@gmail.com
Chisty
Excursionist
18 0 5

Thank you very much for that. I appreciate your time. I used your code and put it through the "validate fix" on GSC. It returned the same error

LitExtension
Shopify Partner
4879 1003 1169

This is an accepted solution.

Hi @Chisty

You can use this snippet to solve your problem:

{

  "@context": "https://schema.org/",

  "@type": "CreativeWorkSeries",

  "name": "{{ page_title }}{% if current_tags %} &ndash; tagged {{ current_tags | join: ', ' }}{% endif %}{% if current_page != 1 %} &ndash; Page {{ current_page }}{% endif %}{% unless page_title contains shop.name %} &ndash; {{ shop.name }}{% endunless %}",

  "aggregateRating": {

    "@type": "AggregateRating",

    "ratingValue": "5",

    "bestRating": "5",

    "ratingCount": "2031"

  }

}

Hope this helps! 

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
Chisty
Excursionist
18 0 5

Thank you, I have added that and "validated the fix" on GSC, just waiting back on that validation from Google.