← 返回基因目录

json-validator

Native data.validate

Validates JSON data against a JSON Schema definition, returning detailed validation errors with paths.

版本
0.1.0
评分
0.36
下载量
0
创建时间
2026年3月17日
更新时间
2026年3月18日
安装
$ rotifer install json-validator copy

评分构成

基因评分 0.36
竞技场 50%
0.72
使用量 30%
0.00
稳定性 20%
0.01

Arena 历史

日期 适应度 安全分 调用数
3月17日 0.7200 0.77 1

README

json-validator

A Native Gene that validates JSON data against a JSON Schema definition.

Usage

rotifer test json-validator --input '{
  "data": {"name": "Alice", "age": "not-a-number"},
  "schema": {
    "type": "object",
    "properties": {
      "name": {"type": "string"},
      "age": {"type": "number"}
    },
    "required": ["name", "age"]
  }
}'

Features

  • Full JSON Schema Draft-07 validation
  • Detailed error messages with JSON path locations
  • Strict mode for disallowing extra properties
  • Nested schema support

Input

Field Type Required Description
data any Yes The JSON data to validate
schema object Yes JSON Schema definition
strict boolean No Disallow additional properties (default: false)

Output

Field Type Description
valid boolean Whether validation passed
errors array Validation errors with path, message, keyword
errorCount number Total error count

Phenotype

inputSchema

{
  "type": "object",
  "required": [
    "data",
    "schema"
  ],
  "properties": {
    "data": {
      "description": "The JSON data to validate (any type)"
    },
    "schema": {
      "type": "object",
      "description": "JSON Schema to validate against"
    },
    "strict": {
      "type": "boolean",
      "default": false,
      "description": "Disallow additional properties not in schema"
    }
  }
}

outputSchema

{
  "type": "object",
  "properties": {
    "valid": {
      "type": "boolean",
      "description": "Whether the data passes validation"
    },
    "errors": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "path": {
            "type": "string",
            "description": "JSON path to the error (e.g. $.items[0].name)"
          },
          "keyword": {
            "type": "string",
            "description": "The schema keyword that failed (e.g. type, required)"
          },
          "message": {
            "type": "string",
            "description": "Human-readable error message"
          }
        }
      },
      "description": "List of validation errors (empty if valid)"
    },
    "errorCount": {
      "type": "number",
      "description": "Total number of validation errors"
    }
  }
}