nebulous
nebulous

Reputation: 766

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?

Upvotes: 12

Views: 4289

Answers (2)

Barney Szabolcs
Barney Szabolcs

Reputation: 12524

In my experience RTL characters (in particular, Persian letters in querystrings) can be problematic for Google, so they have to be encoded in an LD+JSON that is meant to be digested by Google.

CJK characters are fine, if left unencoded.

Upvotes: 0

bhspencer
bhspencer

Reputation: 13570

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

Upvotes: 1

Related Questions