Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should JSON-LD strings be escaped?

Should string values within JSON-LD content be escaped? For instance, Google recommends the following to provide hints for sitesearch:

<script type="application/ld+json">
{
   "@context": "http://schema.org",
   "@type": "WebSite",
   "url": "https://www.example-petstore.com/",
   "potentialAction": {
     "@type": "SearchAction",
     "target": "https://query.example-petstore.com/search?q={search_term_string}",
     "query-input": "required name=search_term_string"
   }
}
</script>

But what if my site's search URL contains multiple query parameters? Should, or can, characters within the value for target be escaped? For instance:

"target": "https://query.example-petstore.com/search?foo=bar\u0026q={search_term_string}",

The same question applies to several common schema.org types when marking up in JSON-LD. Google+ social profile links in Organization->sameAs for example: If my organization's profile is

https://plus.google.com/+BeardsAreSweet

should that be represented as:

"sameAs": ["https://plus.google.com/+BeardsAreSweet"]

or

"sameAs": ["https://plus.google.com/\u002bBeardsAreSweet"]

More importantly, does it matter at all?

like image 499
nebulous Avatar asked Mar 18 '26 23:03

nebulous


1 Answers

It is not necessary to escape your url when it is part of a JSON object. A valid url string is a valid JSON string. A JSON String can contain:

Any UNICODE character except \ or " or control character

http://json.org

like image 65
bhspencer Avatar answered Mar 21 '26 00:03

bhspencer