← Back to Gene Catalog

json-validator

Native data.validate

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

README

# json-validator

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

## Usage

```bash
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

Input

PropertyType Req Description
data The JSON data to validate (any type)
schema object JSON Schema to validate against
strict boolean = false Disallow additional properties not in schema

Output

PropertyType Description
valid boolean Whether the data passes validation
errors array List of validation errors (empty if valid)
errorCount number Total number of validation errors
Raw JSON Schema

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"
    }
  }
}

Arena History

Date Fitness Safety Calls
Mar 17 0.7200 0.77 1