package
Structured Data Validator
npm install @adobe/structured-data-validatorGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Estimated unpacked size across 1 packages.
99.3 kB
Includes dependencies.
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.
npm install @adobe/structured-data-validatorThis 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 HTML
const extractor = new WebAutoExtractor({ addLocation: true, embedSource: ['rdfa', 'microdata'] });
const extractedData = extractor.parse(sampleHTML);
// Fetch the current schema.org schema
const schemaOrgJson = await (await fetch('https://schema.org/version/latest/schemaorg-all-https.jsonld')).json();
// Create a validator instance
const validator = new Validator(schemaOrgJson);
// Validate the extracted structured data
The validator expects the output format from @marbec/web-auto-extractor, which includes:
The validator returns an array of validation issues. Each issue object contains:
issueMessage - Human-readable error or warning messageseverity - Either 'ERROR' or 'WARNING'path - Array representing the location in the data structure where the issue occurredfieldNames - 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)Example validation result:
[
{
issueMessage: 'Required attribute "price" is missing',
severity: 'ERROR',
path: [{ type: 'Product', index: 0 }],
fieldNames: ['price'],
location: '35,100',
},
];You can run the parser and validator directly in the browser on any website using the following commands:
const { default: WebAutoExtractor } =
await import('https://unpkg.com/@marbec/web-auto-extractor@latest/dist/index.js');
const { default: Validator } =
await import('https://unpkg.com/@adobe/structured-data-validator@latest/src/index.js');
const extractedData = new WebAutoExtractor({
addLocation: true,
embedSource: ['rdfa', 'microdata'],
}).parse(document.documentElement.outerHTML);
console.log(extractedData);
const schemaOrgJson = await (
await fetch('https://schema.org/version/latest/schemaorg-all-https.jsonld')
).json();
await newnpm installnpm test - Run tests with coveragenpm run lint - Run ESLintnpm run format - Check code formattingnpm run format:fix - Fix code formatting issuesTo enable debug logging and see detailed validation output, set the debug property to true on your Validator instance:
const validator = new Validator();
validator.debug = true; // Enable debug loggingThis will print additional information to the console during validation, which is useful for development and troubleshooting.
tripod
tripod@bocanegra.ch
adobe-admin
grp-opensourceoffice@adobe.com
patrickfulton
patrickfulton@gmail.com
trieloff
lars@trieloff.net
krisnye
krisnye@gmail.com
dcpfsdk
dcpfsdk@adobe.com
natebaldwin
natebaldwindesign@gmail.com
devongovett
devongovett@gmail.com
aspro83
danniintheus@gmail.com
symanovi
symanovi@adobe.com
dpfister
dominique.pfister@gmail.com
stefan-guggisberg
sg@adobe.com
rofe
npm@rofe.com
kptdobe
kptdobe@gmail.com
adobehalls
halls@adobe.com
fullcolorcoder
bradjohn@adobe.com
djaeggi
djaeggi@adobe.com
dylandepass
dylandepass@gmail.com
mhaack
mhaack@adobe.com
amol-anand
amol@adobe.com
stopp-adobe
stopp@adobe.com
namarora
namarora@adobe.com
doten
doten@adobe.com
duh_schmidt
schmidt@adobe.com
asthabh23
astha.bhargava23@gmail.com
aljoseph
aljoseph@adobe.com
zdahbi
zouhir.dahbi@outlook.com
tuicu
tuicu@adobe.com
fmeschbe
fmeschbe@adobe.com