Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

PHPbeginnercliAI generated

JSON Config Validator

Build a PHP command-line tool that checks JSON configuration files against a set of rules and explains exactly what's wrong, pointing to the precise location of each problem, such as database.port: must be between 1 and 65535, got 70000, or services[2].url: missing required field. The rules are written as a JSON Schema, the standard way to describe what valid JSON looks like, and the tool reports every problem at once, not just the first. It can check many files in one run and fits in a CI pipeline. It's a good first PHP project with Composer: you'll learn command-line scripts, parsing JSON with clear error messages, JSON Schema, using a library from Packagist, formatting output, exit codes, and testing with PHPUnit.

Estimate
~6h
Steps
5
Completed by
0
Proposed by
codeseed.app

PHP CLI · Composer · JSON Schema · PHPUnit

Project roadmap

  1. 01

    Define the tool

    ~1h

    Write README.md: the command (validate-config --schema schema.json config1.json config2.json), the output format (one line per problem with the file, the path such as database.port, and the message), the exit codes (0 all valid, 1 some invalid and 2 usage or file errors), and --format json for machine-readable output. Create the project with composer init. Done when: README.md shows the command, output and exit codes.

  2. 02

    Write a schema

    ~1h

    Write an example config.json for a small app (server host and port, database settings, a list of services with names and URLs, and feature flags) and a JSON Schema describing it: types, required fields, number ranges, string patterns and formats (such as uri), enums, and no unknown fields (additionalProperties false). Done when: the schema describes every rule for the example config.

  3. 03

    Parse the files

    ~1h

    Read each file, and decode it with json_decode and JSON_THROW_ON_ERROR, catching JsonException to report syntax errors clearly with the file name (and the line, found by scanning the text near the error where possible). Report missing and unreadable files and continue with the others. Done when: a file with a syntax error is reported with a clear message.

  4. 04

    Validate and report

    ~1.5h

    Install a JSON Schema library with Composer (such as opis/json-schema or justinrainbow/json-schema), validate each decoded file against the schema, and turn every error into a line with the file, the path in dot and bracket notation, and a readable message. Print a summary (files checked, valid and invalid) and use the right exit code. Add --format json. Done when: a config with several mistakes lists all of them with exact paths.

  5. 05

    Test it

    ~1.5h

    Install PHPUnit and write tests with sample config files: a valid file, each kind of rule broken (type, required, range, pattern, enum and unknown field), invalid JSON, a missing file, several files in one run, and the exit codes. Done when: vendor/bin/phpunit passes.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~6h · 5 steps

Tech stack

PHP CLIComposerJSON SchemaPHPUnit