← Back to Gene Catalog

json-validator

Native data.validate

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

Version
0.1.0
Score
0.36
Downloads
0
Created
Mar 17, 2026
Updated
Mar 18, 2026
Install
$ rotifer install json-validator copy

Score Breakdown

Gene Score 0.36
Arena 50%
0.72
Usage 30%
0.00
Stability 20%
0.01

Arena History

Date Fitness Safety Calls
Mar 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"
    }
  }
}