This is a continuation of a previous topic, from two years ago:
Long story short, when using json-ld structured data, strings with apostrophes turn into \x26rsquo;.
The previous thread mentioned using | safeJS for an old version of Hugo. I’m using 0.55.6 and it didn’t work. What did work was this sequence of functions: | safeJS | htmlUnescape | plainify.
However, if the string contains a url with the + sign, it also returns invalid data for Json-ld. For example: https:\/\/plus.google.com\/u\/0\/\x2b
If your Title is something like Bla & Fasel then yes, it is valid JSON without quotes. Because you just transferred it’s meaning into IF variable Bla and variable Fasel is set which at Google resolves to NOPE because those variables don’t exist in the context of your JSON
As long as it’s a string you will require quotes.
I did not read through the original post, but in my opinion it’s something about urlencode. I am relatively sure Hugo has something for that. That will encode only &# and some special characters I think.
Can you point me to an URL online where you are using this shortcode? I can’t believe it works for the reasons laid out before. I assume whatever validation tool you are using is dropping all after dateModified.
Please test your code with content that contains : (meaning a new parameter is introduced) or , (meaning next parameter will be introduced).
That website has quotes around all entries. Are you sure the template above is coming into play? If so I wonder where the quotes come from. If that is something Hugo does then good.
–
In general: according to the standard only strings WITHOUT whitespace or special characters are allowed to be without quotes. In their samples they even quote the dates:
Well then it’s clear that if there were quotes around those quoted content they cancelled themself out like ""content"". Weird. I wonder if that is a bug.
I don’t want to be a pest, but here: https://brunoamaral.eu/story/museum-tour/
If you check this article on the Structured Data Tool it drops errors, because of the ' in the title.
As I was saying: Try using htmlescape (which is the function I guess will mask all these special characters fully). Maybe in connection with safejs it will go well.
After that I still think there should be quotes around all strings. Some day somewhere this will be fixed and your templates stop again working.
What I am trying to say is that those special characters need to be marked by &-entities, not \-entities.
Thanks for noticing, I have fixed it now. And I am keeping a comment in the source code with the link for this thread in case i come into problems in the future.
| safeJS | htmlUnescape | plainify fixes some of my content, but doesn’t handle ampersands correctly. I also tried htmlescape, but that doesn’t resolve the issue. It does seem like there is a bug in terms of how these strings are being processed. For now, I’m working around it by rewriting quotes and HTML special chars out of my content, since this is just impacting the page description for me currently.