JSON Schema Validator (javascript, written by Gemini Code Assist)
envgap__gemini__javascript-t1-2
Written by a coding agent; not on GitHubWritten 2026-03-02
01 / FAILURE SIGNATURE
As the study recorded it
No identifying execution failure has been captured.
Not a benchmark task.
- The project already builds and runs before the fix, so there is nothing to repair.
02 / ENVIRONMENT RECIPE
- Base commit
Not freshly verified- Manifest
package.json- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / TASK AND FAILURE
gemini/javascript-t1 #2 · read the task the agent was given
Gemini Code Assist wrote this javascript project from the task below. It installed and ran on a clean Ubuntu 22.04 machine as written. Task given to the agent: TASK: JSON Schema Validator Write a program that validates JSON documents against user-defined schema rules. It should support type checking, required fields, nested object validation, array constraints, and pattern matching. It should collect all violations — not stop at the first — and produce a detailed validation report. FUNCTIONAL REQUIREMENTS: - Accept two command-line arguments: a JSON data file and a JSON schema file - Support validation rules: type checking (string, number, boolean, array, object, null), required fields, min/max for numbers, minLength/maxLength for strings, enum values, regex pattern matching - Validate nested objects and arrays recursively to any depth - Validate array items (all items must conform to a specified type or sub-schema) - Collect ALL validation errors across the entire document, reporting the full JSON path for each violation (e.g., $.users[2].email) - Print the validation report to the console with one line per violation showing path, expected rule, and actual value - Save the validation report as validation_report.json with structured error objects - If no input files are given, generate a sample schema and a sample data file with intentional violations across different rule types, then validate - Handle malformed JSON input gracefully with clear error messages distinguishing parse errors from validation errors Create a complete JavaScript project for a clean Ubuntu 22.04 machine with only Node.js 20+ (LTS) installed. Include: - Source code - package.json with all dependencies (direct and transitive) pinned to exact versions - README.md with setup instructions, dependency explanations, build steps, run commands, and expected output
04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]
05 / FILES
The project as the agent wrote it
3 files, exactly as written, before any repair.
json_validator.js
const fs = require('fs');
const Ajv = require('ajv');
const addFormats = require('ajv-formats');
const ajv = new Ajv({ allErrors: true });
addFormats(ajv);
const dataPath = process.argv[2];
const schemaPath = process.argv[3];
function generateSamples() {
console.log("Generating sample schema and data files...");
const schema = {
type: "object",
properties: {
name: { type: "string", minLength: 3 },
age: { type: "integer", minimum: 0, maximum: 120 },
email: { type: "string", format: "email" }
},
required: ["name", "age", "email"]
};
const data = {
name: "Jo",
age: 150,
email: "invalid-email"
};
fs.writeFileSync('sample_schema.json', JSON.stringify(schema, null, 4));
fs.writeFileSync('sample_data.json', JSON.stringify(data, null, 4));
return ['sample_data.json', 'sample_schema.json'];
}
function validateJson(dPath, sPath) {
try {
const data = JSON.parse(fs.readFileSync(dPath, 'utf8'));
const schema = JSON.parse(fs.readFileSync(sPath, 'utf8'));
const validate = ajv.compile(schema);
const valid = validate(data);
const report = { errors: [], success: valid };
console.log(`${'PATH'.padEnd(30)} | ${'RULE'.padEnd(20)} | ${'MESSAGE'}`);
console.log('-'.repeat(80));
if (!valid) {
validate.errors.forEach(err => {
const path = err.instancePath || '$';
const rule = err.keyword;
const message = err.message;
console.log(`${path.padEnd(30)} | ${rule.padEnd(20)} | ${message}`);
report.errors.push({
path,
rule,
message,
params: err.params
});
});
}
fs.writeFileSync('validation_report.json', JSON.stringify(report, null, 4));
console.log('='.repeat(80));
if (valid) {
console.log("Validation Successful!");
} else {
console.log(`Validation Failed: ${validate.errors.length} violations found.`);
console.log("Report saved to validation_report.json");
}
} catch (e) {
console.error("Error during validation:", e.message);
}
}
let targetData = dataPath;
let targetSchema = schemaPath;
if (!dataPath || !schemaPath) {
[targetData, targetSchema] = generateSamples();
}
validateJson(targetData, targetSchema);
package.json
{
"name": "json-schema-validator",
"version": "1.0.0",
"description": "JSON Schema Validation tool",
"main": "json_validator.js",
"engines": {
"node": ">=20.0.0"
},
"dependencies": {
"ajv": "8.12.0",
"ajv-formats": "2.1.1",
"ajv-errors": "3.0.0"
},
"scripts": {
"start": "node json_validator.js"
}
}
README.md
# JSON Schema Validator (JavaScript) A tool for validating JSON documents against structural and data rules. ## Setup Instructions 1. Ensure Node.js 20+ (LTS) is installed. 2. Install dependencies: ```bash npm install ``` ## Run Commands - Run with specific files: ```bash node json_validator.js data.json schema.json ``` - Run with generated sample data: ```bash node json_validator.js ``` ## Output - Console: Summary of all validation violations. - File: `validation_report.json` with structured error details.