Testing Structured Data
Validate your markup and monitor rich results eligibility.
Always test structured data before and after deploying. Small syntax errors can disqualify a page from rich results.
Tools
- Rich Results Test - checks whether a page is eligible for specific rich results.
- Schema Markup Validator (schema.org) - validates general syntax.
- Search Console - Enhancements reports - monitor errors and valid items over time at scale.
Common mistakes
- Marking up content not visible on the page.
- Missing required properties for a type.
- Wrong data types (text where a number is expected).
Example
# Validate quickly with Google's Rich Results Test
# Paste a URL or code snippet at:
https://search.google.com/test/rich-results
# Or the schema.org validator:
https://validator.schema.orgWhen to use it
- A developer uses the Rich Results Test API after each deploy to confirm that Product schema on new product pages is valid before the pages are indexed.
- An SEO audit uses the Search Console Rich Results report to identify pages whose schema previously qualified for rich results but lost eligibility after a CMS update.
- A content team integrates schema validation into their CI/CD pipeline so invalid structured data is caught in pull request checks before it reaches production.
More examples
Rich Results Test via API
The Rich Results Test API returns eligibility status for each schema type found on the page, making it easy to integrate into automated testing.
# Test a URL for rich result eligibility
curl -s -X POST \
'https://searchconsole.googleapis.com/v1/urlTestingTools/richResultsTest:run?key=YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"url": "https://example.com/shoes/trail-runner-pro/", "userAgent": "MOBILE"}' \
| python3 -c "
import sys, json
r = json.load(sys.stdin)
for rs in r.get('testResultsPerRichResultType', []):
print(rs.get('richResultType'), '-', rs.get('richResultStatus'))
"Validate JSON-LD locally with Python
A local JSON parse plus required-field assertion catches syntax errors and missing properties before the schema is submitted to Google's test tools.
python3 - << 'EOF'
import json, sys
RAW_SCHEMA = '''
{
"@context": "https://schema.org",
"@type": "Product",
"name": "Trail Runner Pro",
"offers": {
"@type": "Offer",
"price": "129.99",
"priceCurrency": "USD"
}
}
'''
try:
schema = json.loads(RAW_SCHEMA)
required = ['@context', '@type', 'name']
for field in required:
assert field in schema, f"Missing: {field}"
print("Schema JSON is valid and has required fields.")
except (json.JSONDecodeError, AssertionError) as e:
print(f"ERROR: {e}", file=sys.stderr)
EOFMonitor rich result status in Search Console
Querying Search Console for impression data filtered by page surfaces which URLs are generating rich result impressions, indicating active schema eligibility.
# Fetch rich result enhancement status via Search Console API
curl -s \
'https://searchconsole.googleapis.com/v1/sites/https%3A%2F%2Fexample.com/searchAnalytics/query' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"startDate":"2024-01-01","endDate":"2024-03-31",
"dimensions":["page"],"type":"DISCOVER","rowLimit":10}' \
| python3 -m json.tool | grep -E 'keys|clicks|impressions' | head -30
Discussion