11

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?

2 Answers 2

1

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

2
  • 2
    What I'm primarily concerned with is not what is permitted in json, but how the string will be interpreted. For instance, in the "sameAs" example, would google interpret both strings equally? They both represent the same value when decoded, but are they decoded prior to evaluation? I didn't see anything in the spec about that.
    – nebulous
    Apr 15, 2015 at 22:10
  • 3
    The question is sill not answered! I also want to know: when a parameter in LD-JSON should have the value https://example.com/search?q=abc&filter=true, is it OK when I use the escaped version https://example.com/search?q=abc&amp;filter=true ??? Please help
    – basZero
    Jan 23, 2020 at 10:29
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.