How to fix invalid rating value on Next.js (Headless)

Fix the AggregateRating.ratingValue in your structured data so it is a valid number between 1 and 5 (or your declared scale's minimum and maximum).

Steps for Next.js (Headless)

  1. Locate the product page component that renders JSON-LD structured data — typically `app/products/[slug]/page.tsx` (App Router) or `pages/products/[slug].tsx` (Pages Router).
  2. Find the `AggregateRating` object inside your JSON-LD script and identify where `ratingValue` is sourced (e.g. raw API field, CMS field, or a manual constant).
  3. Clamp and sanitise the value before injecting it: parse it as a float, ensure it is a finite number, then clamp it between `bestRating` (max, default 5) and `worstRating` (min, default 1). Never pass `null`, `undefined`, `NaN`, or an out-of-range value.
  4. Ensure `bestRating`, `worstRating`, and `reviewCount` are also present in the `AggregateRating` block — Google requires all four fields for the rating to be valid.
  5. Inject the sanitised object via a `<script type='application/ld+json'>` tag: use Next.js `<Script id='...' type='application/ld+json'>` (from `next/script`) inside the component, or return it from `generateMetadata` / use the App Router's built-in JSON-LD pattern.
  6. Validate the output in Google's Rich Results Test (https://search.google.com/test/rich-results) to confirm the rating is parsed correctly and no warnings remain.
Official Next.js (Headless) documentation ↗

What is invalid rating value?

Structured data is hidden code on your product pages that tells search engines facts about your store — things like star ratings, prices, and product names. The `AggregateRating` block specifically communicates your average customer rating. The `ratingValue` field inside that block must be a real number (e.g. 4.3) that falls between the declared minimum and maximum rating values — typically 1 to 5. When it is missing, set to 0, left blank, or formatted incorrectly, search engines consider the entire rating block invalid.

A valid `AggregateRating` is what earns you gold star snippets in Google Search results — those eye-catching stars visible directly on the results page before a shopper even clicks. Stores with star snippets consistently see higher click-through rates, which drives more organic traffic and sales. An invalid or zero `ratingValue` means Google ignores your rating markup entirely, stripping those stars from your listing and handing the visual advantage to competitors. For Answer Engine Optimisation (AEO), valid rating structured data also influences how AI-powered answer engines and shopping assistants surface and rank your products in direct answers.

See the complete Invalid rating value guide for every platform and the full background.

Not sure if your Next.js (Headless) store has this?

Run a free SEOLZ scan — we’ll find invalid rating value and every other issue across your whole site.

Scan my site free

Fix invalid rating value on another platform