htmljsonhtml-entitiesjson-ldstructured-data

Can you use HTML entities in JSON-LD?


I am planning to add JSON-LD on some web pages and some have the letter enye (ñ). I had previously replaced the letter with the HTML entity ñ, but later realized the ñ in the JSON-LDwas also replaced. Is this valid JSON-LD, and will it not cause errors in Google if rich results will be generated:

{
 "@context": "https://schema.org",
  "@type": "Place",
  "name": "Santo Niño"
}

Solution

  • Using entities is fine in embedded JSON-LD, as it is still a valid JSON string, however do not expect the entities to be replaced with their UTF-8 equivalents. As described in Section 7.2 of the JSON-LD Syntax spec

    Authors should avoid using character sequences in scripts embedded in HTML which may be confused with a comment-open, script-open, comment-close, or script-close.

    NOTE

    Such content should be escaped as indicated below, however the content will remain escaped after processing through the JSON-LD API.

    This is an HTML processing rule for data script elements, and not specific to JSON-LD.