Loops

Fix Invalid JSON Data Files

Finds every JSON file that fails to parse or match its schema and repairs it.

Anyone with a folder of JSON data files, generated or hand-edited, that may have gotten malformed or drifted from the expected shape.

The problem

A single missing comma or wrong field type can break a JSON file, and with many files you cannot tell which ones are broken without opening each one. Checking every file by eye against what the shape should be is slow and unreliable.

1. Work list

The command that lists every item. No AI involved.

find ./data -name '*.json'

2. Unit of work

One item is one JSON file.

3. The check

The checker runs jq empty <file> to confirm it parses, then, if a schema file exists, npx ajv validate -s schema.json -d <file>. Exit code 0 if both pass. Exit code 1 if jq reports a parse error or ajv reports a schema violation, printing the exact error back to the AI.

4. Stopping rule

Each file gets up to 3 repair attempts before quarantine, ending once every file in the work list has been checked.

What this cannot catch

Valid JSON that matches the schema can still hold wrong values, like a price of 0 or a name that is a placeholder.

Build it

Install justloopit, then describe this task in your AI coding tool. It will ask about your project, then write the checker, the runner, and the spec.

Install

Build a loop