A JavaScript library for validating and parsing structured data according to Schema.org specifications and Google Rich Results requirements. This library ensures your structured data meets both Schema.org standards and Google's specific requirements for rich results, helping to optimize your content for search engines and other platforms.
Features
Validates structured data against both Schema.org and Google Rich Results specifications
Ensures compliance with Google's structured data guidelines
Extensible validation system with custom type handlers
Installation
npm install @adobe/structured-data-validator
Usage
This library works in conjunction with @marbec/web-auto-extractor to validate structured data extracted from web pages.
import { Validator } from '@adobe/structured-data-validator';import WebAutoExtractor from '@marbec/web-auto-extractor';// First, extract structured data from HTMLconst extractor = new WebAutoExtractor({ addLocation: true, embedSource: ['rdfa', 'microdata'] });const extractedData = extractor.parse(sampleHTML);// Fetch the current schema.org schemaconst schemaOrgJson = await (await fetch('https://schema.org/version/latest/schemaorg-all-https.jsonld')).json();// Create a validator instanceconst validator = new Validator(schemaOrgJson);// Validate the extracted structured data
The validator expects the output format from @marbec/web-auto-extractor, which includes:
JSON-LD structured data
Microdata
RDFa
Validation Results
The validator returns an array of validation issues. Each issue object contains:
issueMessage - Human-readable error or warning message
severity - Either 'ERROR' or 'WARNING'
path - Array representing the location in the data structure where the issue occurred
fieldNames - Array of field paths that caused the validation issue (e.g., ['price'], ['offers.price'], or ['aggregateRating', 'offers', 'review'] for compound conditions)
location - Character position in the original source (if available)