Question presented to candidate: "How would you add Product structured data to a product page in Next.js, and what security issue must you handle when the data comes from users?"
What a strong answer should cover:
- JSON-LD is schema.org data in a
script type="application/ld+json"tag that search engines read for rich results. - In Next.js render it from the page or layout as a script element with
dangerouslySetInnerHTMLandJSON.stringify(data). - Escape
<(for example replace it with the unicode escape\u003c), otherwise a value containing a closing script tag ends the tag early and the rest becomes HTML. - It is not part of the Metadata API; it is rendered in the component tree, and the page renders on the server so crawlers see it.
- Validate the output with Google Rich Results Test and keep it consistent with visible content.
Clarifying questions expected:
- "Which schema types matter (Product, Article, FAQ, Breadcrumb)?" β decides the fields.
- "Is any field user-generated?" β then escaping is mandatory.
Code / implementation expected: Yes β a safe JSON-LD script in a page.