Skip to content

How to Validate JSON Data Before Publishing

Last Updated: August 26, 2026

Why Invalid JSON Silently Breaks Your SEO

Structured data markup in JSON-LD format directly controls whether your pages display rich results in Google Search. Recipe cards, FAQ accordions, product ratings, event listings, and how-to steps all depend on valid JSON-LD. A single syntax error in your schema markup does not produce a visible warning on your page. The page looks normal to visitors, but Google silently ignores the broken structured data, and you lose every rich result opportunity for that page.

A trailing comma after the last property, a missing closing brace, or a single quote instead of a double quote is enough to break everything. Google's Rich Results Test validates your structured data and identifies the exact error, but most site owners never run this test after publishing new content.

JSON Syntax Rules You Must Follow

JSON has zero tolerance for syntax deviations. Every rule exists for a reason, and every violation causes a parsing failure:

  • Strings must use double quotes, never single quotes: "value" is valid, 'value' is not
  • Keys must be double-quoted strings: {"key": "value"} is valid, {key: "value"} is not
  • No trailing commas after the last property or array element: {"a": 1, "b": 2} is valid, {"a": 1, "b": 2,} is not
  • No comments anywhere in the JSON: JSON does not support // or /* */ style comments
  • Values can be strings, numbers, booleans (true/false), arrays, objects, or null
  • Arrays and objects must be properly closed: [] for arrays, {} for objects

A valid Product schema looks like this:

{
  "@context": "https://schema.org",
  "@type": "Product",
  "name": "Wireless Bluetooth Headphones",
  "image": "https://example.com/headphones.jpg",
  "description": "Noise-cancelling wireless headphones with 30-hour battery",
  "brand": {
    "@type": "Brand",
    "name": "AudioTech"
  },
  "offers": {
    "@type": "Offer",
    "price": "79.99",
    "priceCurrency": "USD",
    "availability": "https://schema.org/InStock"
  }
}

Every brace, bracket, comma, and colon must be exactly right. Our JSON validator checks your structured data against these rules and pinpoints the exact line and character where errors occur.

Validating with Google's Tools

Google provides two essential tools for structured data validation. The Rich Results Test (search.google.com/test/rich-results) checks whether your JSON-LD produces valid rich results and identifies syntax errors, missing required properties, and invalid values. The Schema Markup Validator (validator.schema.org) performs deeper validation against schema.org specifications beyond what Google requires.

Run both tests every time you add or modify structured data. The Rich Results Test tells you what Google can actually display. The Schema Markup Validator catches additional issues that might not affect rich results today but could become problems as Google's requirements evolve.

For bulk validation across your entire site, use our schema validator. It crawls your pages and checks every JSON-LD block for syntax validity and Google compliance, producing a report that highlights which pages have broken or incomplete structured data.

Programmatic Validation in PHP

If your site generates structured data dynamically, validate it before outputting it to the page. PHP's json_decode function returns null when JSON is invalid, and json_last_error provides the specific error:

<?php
$schema = json_encode([
    '@context' => 'https://schema.org',
    '@type' => 'Article',
    'headline' => $post->title,
    'author' => [
        '@type' => 'Person',
        'name' => $post->author->name,
    ],
]);

// Validate before outputting
$data = json_decode($schema);
if (json_last_error() !== JSON_ERROR_NONE) {
    error_log('Schema validation failed: ' . json_last_error_msg());
    // Fall back to no schema rather than broken schema
    $schema = '';
}
?>
<script type="application/ld+json">
{!! $schema !!}
</script>

Adding this validation check to your template layer prevents broken structured data from ever reaching your pages. Log validation failures so you can identify and fix issues proactively rather than discovering them weeks later in Search Console.

Programmatic Validation in JavaScript

When working with API responses or dynamic content, validate JSON before processing it. Wrap JSON.parse in a try-catch block to handle errors gracefully:

try {
    const data = JSON.parse(jsonString);
    console.log("Valid JSON - processing", Object.keys(data).length, "keys");
} catch (e) {
    console.error("Invalid JSON:", e.message);
    // Report to error monitoring or show user-friendly message
}

// Validate structured data already rendered on the page
document.querySelectorAll('script[type="application/ld+json"]').forEach((script, i) => {
    try {
        const data = JSON.parse(script.textContent);
        console.log(`Schema ${i + 1}: Valid - @type: ${data["@type"]}`);
    } catch (e) {
        console.error(`Schema ${i + 1}: INVALID - ${e.message}`);
    }
});

Add JSON validation to your CI/CD pipeline using jsonlint (npm install -g jsonlint). Run jsonlint on every JSON file in your repository before deployment to catch syntax errors before they reach production:

jsonlint schema.json
jsonlint src/config/*.json

Common JSON Errors That Break Rich Results

The most frequent error is trailing commas. Developers accustomed to JavaScript allow them habitually: {"price": 99, "currency": "USD",} fails JSON parsing. The fix: remove the comma after the last property.

Missing quotes around keys is the second most common error: {price: 99} should be {"price": 99}. Single quotes throughout the JSON must be replaced with double quotes. Unescaped backslashes in string values cause parsing failures: {"path": "C:\\Users"} requires double backslashes or forward slashes.

Wrong data types also cause silent failures. Schema.org often expects strings for prices: "price": "99.99" is correct, "price": 99.99 may cause validation warnings. Availability must be a URL string: "availability": "https://schema.org/InStock", not a plain text value like "InStock".

Validate every structured data block before deploying to production. Our JSON validator catches these issues instantly and explains what each error means in plain language so you can fix them quickly.

Testing Structured Data in Staging

Before deploying JSON-LD changes to production, test them in your staging environment using Google's Rich Results Test. Paste the staging URL and verify that all structured data validates correctly. Check that required properties like name, image, and offers for Product schema are present and properly formatted.

Monitor Google Search Console's Enhancements reports after deploying structured data changes. The Product, FAQ, and How-To reports show which pages have valid markup and which have errors. Address errors within 48 hours of deployment because Google caches structured data validation results, and lingering errors can delay rich result eligibility for weeks.

Our JSON validator also supports batch validation for sites with hundreds or thousands of pages. Upload a list of URLs or paste multiple JSON-LD blocks at once to validate your entire site's structured data in a single operation, saving hours compared to manual testing page by page.