JSON Schema Validator (cpp, written by Gemini Code Assist)
envgap__gemini__cpp-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
CMakeLists.txt- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / TASK AND FAILURE
gemini/cpp-t1 #2 · read the task the agent was given
Gemini Code Assist wrote this cpp 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 C++ project for a clean Ubuntu 22.04 machine with only G++ 12+ and CMake 3.22+ installed. Include: - Source code - CMakeLists.txt 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.
CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(JsonSchemaValidator)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
# Pinned nlohmann/json
FetchContent_Declare(
json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
)
# Pinned valijson for schema validation
FetchContent_Declare(
valijson
GIT_REPOSITORY https://github.com/tristanpenman/valijson.git
GIT_TAG v0.7
)
FetchContent_MakeAvailable(json valijson)
add_executable(json_validator main.cpp)
target_include_directories(json_validator PRIVATE ${valijson_SOURCE_DIR}/include)
target_link_libraries(json_validator PRIVATE nlohmann_json::nlohmann_json)
main.cpp
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
#include <valijson/adapters/nlohmann_json_adapter.hpp>
#include <valijson/utils/nlohmann_json_utils.hpp>
#include <valijson/schema.hpp>
#include <valijson/schema_parser.hpp>
#include <valijson/validator.hpp>
#include <valijson/validation_results.hpp>
using json = nlohmann::json;
using valijson::Schema;
using valijson::SchemaParser;
using valijson::Validator;
using valijson::ValidationResults;
using valijson::adapters::NlohmannJsonAdapter;
void generate_samples() {
std::cout << "Generating sample schema and data files..." << std::endl;
json schema = {
{"type", "object"},
{"properties", {
{"name", {{"type", "string"}, {"minLength", 3}}},
{"age", {{"type", "integer"}, {"minimum", 0}, {"maximum", 120}}},
{"email", {{"type", "string"}}}
}},
{"required", {"name", "age", "email"}}
};
json data = {
{"name", "Jo"},
{"age", 150},
{"email", "invalid-email"}
};
std::ofstream s_out("sample_schema.json");
s_out << schema.dump(4);
std::ofstream d_out("sample_data.json");
d_out << data.dump(4);
}
int main(int argc, char* argv[]) {
std::string dataPath, schemaPath;
if (argc == 3) {
dataPath = argv[1];
schemaPath = argv[2];
} else {
generate_samples();
dataPath = "sample_data.json";
schemaPath = "sample_schema.json";
}
json data, schemaJson;
if (!valijson::utils::loadDocument(dataPath, data)) {
std::cerr << "Failed to load data file" << std::endl;
return 1;
}
if (!valijson::utils::loadDocument(schemaPath, schemaJson)) {
std::cerr << "Failed to load schema file" << std::endl;
return 1;
}
Schema schema;
SchemaParser parser;
NlohmannJsonAdapter schemaAdapter(schemaJson);
parser.populateSchema(schemaAdapter, schema);
Validator validator;
NlohmannJsonAdapter dataAdapter(data);
ValidationResults results;
bool valid = validator.validate(schema, dataAdapter, &results);
json report;
report["success"] = valid;
report["errors"] = json::array();
std::cout << std::left << std::setw(30) << "PATH" << " | " << "MESSAGE" << std::endl;
std::cout << std::string(80, '-') << std::endl;
ValidationResults::Error error;
while (results.popError(error)) {
std::string path = "";
for (const auto& part : error.context) path += part;
std::cout << std::left << std::setw(30) << path << " | " << error.description << std::endl;
report["errors"].push_back({
{"path", path},
{"message", error.description}
});
}
std::ofstream r_out("validation_report.json");
r_out << report.dump(4);
std::cout << std::string(80, '=') << std::endl;
if (valid) {
std::cout << "Validation Successful!" << std::endl;
} else {
std::cout << "Validation Failed. Report saved to validation_report.json" << std::endl;
}
return 0;
}
README.md
# JSON Schema Validator (C++) A tool for validating JSON documents against structural and data rules. ## Setup Instructions 1. Ensure G++ 12+ and CMake 3.22+ are installed. 2. Build the project: ```bash mkdir build && cd build cmake .. make ``` ## Run Commands - Run with specific files: ```bash ./json_validator ../data.json ../schema.json ``` - Run with generated sample data: ```bash ./json_validator ``` ## Output - Console: Summary of all validation violations. - File: `validation_report.json` with structured error details.