Home
1 min read
·
0 views

Enhancing SEO with JSON-LD Structured Data

Search engines like Google use structured data to understand the contents of our page better. JSON-LD is a format that most use to describe the data.

Structured Data

Below is an example of a piece of structured data.

{
  "@context": "https://json-ld.org/contexts/person.jsonld",
  "@id": "http://dbpedia.org/resource/John_Lennon",
  "name": "John Lennon",
  "born": "1940-10-09",
  "spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}

Source: JSON-LD

Adding Structured Data

  1. Create the following component StructuredData.jsx.
export const StructuredData = ({ data }) => {
  return <script type="application/ld+json">{JSON.stringify(data)}</script>;
};
  1. Use the StructuredData component in your respective component containing the UI for your post.
export const BlogPost = ({ post }) => {
  const structuredData = {
    "@context": "https://schema.org",
    "@type": "Article",
    headline: post.title,
    description: post.description,
    author: [
      {
        "@type": "Person",
        name: post.author,
      },
    ],
    image: post.imageUrl,
    datePublished: post.publishedAt,
  };
};
 
return (
  <>
    <Structured data={structuredData} />
    {/* ... the rest of your blog post */}
  </>
);

Validate Structured Data

Before deploying the changes to production, we can inspect the HTML elements on a browser to see if the changes are reflected in the <head> section of the page.

Upon successful deployment, we can use the Schema Markup Validator to validate.