W3C home > Mailing lists > Public > public-schemaorg@w3.org > March 2017

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

From: Robin Berjon <robin@berjon.com>
Date: Mon, 6 Mar 2017 18:12:33 -0500
To: Karen <karen.cravens@gmail.com>, public-schemaorg@w3.org
Message-ID: <39618fcf-4742-e471-f9b7-6884d853506b@berjon.com>
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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:12:34 UTC