← Back to Blog

JSON-LD Structured Data for Articles, Embedded Safely

How to describe a blog post with schema.org JSON-LD in a Next.js page, which properties matter for articles, and why the script tag must escape the less-than sign.

Curly braces around a schema.org article object

JSON-LD is a way to describe a page to machines using the schema.org vocabulary. For a blog post, it tells search engines and other consumers the headline, the author, the publication date and where the canonical page lives. It is not a ranking trick, but it removes guesswork and makes your content eligible for richer treatment where the platform supports it.

A minimal article object

For a technical post, TechArticle is a more specific type than Article and fits well. These are the properties that matter most. Everything else is optional and can be added later.

article JSON-LD

Embed it safely in Next.js

Render the object into a script tag with type application/ld+json. The one thing to get right is escaping. JSON.stringify does not escape the less-than sign, so a string containing a closing script tag would end the block early and inject markup. Replacing < with its Unicode escape keeps the output valid JSON and safe to inline.

components

Keep it in sync with the visible page

Structured data must describe what the reader sees. Do not claim a rating, a price or an author that is not on the page. Generate the object from the same variables that render the title and date, so a change in one place cannot leave the other stale.

Test before you rely on it

Run the live page through a structured data validator and check that the required fields are present and the types are spelled correctly. A missing comma or a misspelled key makes the whole block invalid, and validators will point to the exact line.

OGImg is a dynamic OG image API built on Next.js, Puppeteer, and Cloudflare R2. Learn more →