Re: Embedding JSON with <script> tags inside <script> tags

On 06/03/2017 17:15 , Karen wrote:
> On Mon, Mar 6, 2017 at 4:26 PM, Robin Berjon <robin@berjon.com
> <mailto:robin@berjon.com>> wrote:
> 
>     On 06/03/2017 15:55 , Karen wrote:
>     > My question then is, what's an appropriate way to escape the JSON while
>     > still letting Google et al. parse it properly?
> 
>     If I understand your problem correctly, you need the following (or its
>     equivalent in whatever language you're using):
> 
>       JSON.stringify(obj).replace(/<\/script/gi, '<\\u002fscript');
> 
>     On the text value to set on the LD script element.
> 
> 
> Thanks, but that's not quite the problem - I'm going to have to escape
> the JSON somehow to fix the local page, yes, but the problem is finding
> a way to do it that things that consume it will recognize. Far as I can
> see, there's no standard property on a <script> to indicate that the
> contents need any preprocessing. So if I escape the JSON, I'm expecting
> Google to happily index the sites as being named
> "less-than-aitch-one-greater-than Site Name
> less-than-slash-aitch-one-greater-than" which is... not quite what I want.

There is no need to indicate preprocessing, the escape provided above is
part of the JSON standards (all of them). Consumers will just read it
correctly.

-- 
• Robin Berjon - http://berjon.com/ - @robinberjon
• http://science.ai/ — intelligent science publishing
•

Received on Monday, 6 March 2017 23:13:02 UTC