@adobe/structured-data-validator

中文文档
1.7.0发布于 2026/02/25Apache-2.0ES Module零依赖构建来源已验证近 30 天下载 6.4万

Structured Data Validator

原始使用文档
文档目录11 节
  1. Features
  2. Installation
  3. Usage
  4. Validation Results
  5. Browser
  6. Development
  7. Prerequisites
  8. Setup
  9. Available Scripts
  10. Debug Logging
  11. Dependencies

@adobe/structured-data-validator

GitHub License CI NPM Version Node Current

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 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);
}

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)

Example validation result:

[
  {
    issueMessage: 'Required attribute "price" is missing',
    severity: 'ERROR',
    path: [{ type: 'Product', index: 0 }],
    fieldNames: ['price'],
    location: '35,100',
  },
];

Browser

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 new Validator(schemaOrgJson).validate(extractedData);

Development

Prerequisites

  • Node.js (latest LTS version recommended)
  • npm

Setup

  1. Clone the repository
  2. Install dependencies:
    npm install
    

Available Scripts

  • npm test - Run tests with coverage
  • npm run lint - Run ESLint
  • npm run format - Check code formatting
  • npm run format:fix - Fix code formatting issues

Debug Logging

To 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 logging

This will print additional information to the console during validation, which is useful for development and troubleshooting.

Dependencies

版本与发布记录

@adobe/structured-data-validator 共发布 15 个版本,首次发布于 2025/05/08;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.7.0latest2026/02/258 个月前
1.6.02026/02/029 个月前
1.5.02025/08/201.2 年前
1.4.12025/08/131.2 年前
1.4.02025/08/131.2 年前
1.3.02025/08/071.3 年前

关于 @adobe/structured-data-validator 的常见问题

@adobe/structured-data-validator 是什么?

Structured Data Validator

如何安装 @adobe/structured-data-validator?

在项目目录运行 npm install @adobe/structured-data-validator,或使用 pnpm add / yarn add / bun add。

@adobe/structured-data-validator 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adobe__structured-data-validator 是否存在。

@adobe/structured-data-validator 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@adobe/structured-data-validator 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@adobe/structured-data-validator 可以商用吗?

@adobe/structured-data-validator 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/structured-data-validator 的下载量有多少?

根据 npm 官方下载统计,@adobe/structured-data-validator 在 2026/10/05 – 2026/11/03 这 30 天内被下载 64,005 次,日均约 2,134 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe/structured-data-validator 还在维护吗?

最新版本 1.7.0 发布于 2026/02/25(8 个月前);至今共发布 15 个版本,其中过去 12 个月发布了 2 个;首次发布于 2025/05/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。