Structured Data Validator
npm install @gsriram24/structured-data-validator> Fork of @adobe/structured-data-validator with additional features.

!Node Current
A JavaScript library for validating and parsing structured data according to Schema.org specifications and Google Rich Results requirements.
This fork adds the following features on top of Adobe's original library:
fieldNames array for precise programmatic access:``javascript
// Before (Adobe's version) - requires string parsing
{
issueMessage: 'Required attribute "price" is missing',
severity: 'ERROR',
path: [...]
}
// After (this fork) - direct field access
{
issueMessage: 'Required attribute "price" is missing',
severity: 'ERROR',
path: [...],
fieldNames: ['price'] // ✨ New!
}
`
For or() conditions with multiple fields:`javascript`
{
issueMessage: 'One of the following attributes is required...',
fieldNames: ['aggregateRating', 'offers', 'review'] // All relevant fields
}
Access the primary field with error.fieldNames[0]}, or iterate over all fields as needed.
| Type | Required Fields |
|------|-----------------|
| LocalBusiness | name, address |Article
| | headline |Event
| | name, startDate, location (or online mode) |FAQPage
| | mainEntity |HowTo
| | name, step |WebSite
| | name, url |
| Subtype | Inherits From |
|---------|---------------|
| Restaurant, Store, Hotel, Dentist | LocalBusiness |NewsArticle
| , BlogPosting, TechArticle | Article |MusicEvent
| , SportsEvent, Festival | Event |
This enables validation of 100+ schema types without individual validator files.
---
`bash`
npm install @gsriram24/structured-data-validator
`javascript
import { Validator } from '@gsriram24/structured-data-validator';
import WebAutoExtractor from '@marbec/web-auto-extractor';
// 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
const results = await validator.validate(extractedData);
// Use fieldNames for precise error handling
results.forEach(issue => {
if (issue.severity === 'ERROR') {
console.log(Field "${issue.fieldNames?.[0]}" has error: ${issue.issueMessage});`
}
});
`js
const { default: WebAutoExtractor } = await import(
'https://unpkg.com/@marbec/web-auto-extractor@latest/dist/index.js'
);
const { default: Validator } = await import(
'https://unpkg.com/@gsriram24/structured-data-validator@latest/src/index.js'
);
const extractedData = new WebAutoExtractor({
addLocation: true,
embedSource: ['rdfa', 'microdata'],
}).parse(document.documentElement.outerHTML);
const schemaOrgJson = await (
await fetch('https://schema.org/version/latest/schemaorg-all-https.jsonld')
).json();
const issues = await new Validator(schemaOrgJson).validate(extractedData);
console.log(issues);
`
The features in this fork have been submitted as PRs to the upstream Adobe repository:
- PR #57: Add fieldName property
- PR #58: Add validators for common schema types
Once merged upstream, consider switching back to @adobe/structured-data-validator.
- Node.js (>=18.0.0)
- npm
`bash`
git clone https://github.com/gsriram24/structured-data-validator.git
cd structured-data-validator
npm install
- npm test - Run tests with coveragenpm run lint
- - Run ESLintnpm run format
- - Check code formattingnpm run format:fix` - Fix code formatting issues
-
Apache-2.0 (same as upstream)
Original library by Adobe.