Next.js · Junior · Question 71 of 75
How do you add JSON-LD structured data to a page?
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd).replace(/</g, '\\u003c') }}
/>- ✓Correct answer: Render a
<script type="application/ld+json">with the serialized data in the page component - 2Put it into
metadata.jsonLd - 3Search engines read JSON-LD only from
public/
Explanation
Escaping < prevents XSS through the injected JSON. Types from schema-dts help keep the data valid.