{
  "name": "Batch Format and Validate JSON Files",
  "version": "1.0",
  "description": "Pretty-print, validate, and optionally minify all JSON files in a directory tree.",
  "author": "ToolPilot.dev",
  "url": "https://toolpilot.dev/guides/batch-processing/batch-json-format/",
  "steps": [
    {
      "id": "find_json",
      "tool": "find",
      "description": "Locate all JSON files, excluding node_modules and lock files",
      "command": "find {input_dir} -name '*.json' -not -path '*/node_modules/*' -not -name 'package-lock.json'",
      "defaults": {
        "input_dir": "."
      }
    },
    {
      "id": "validate",
      "tool": "python3",
      "description": "Validate JSON syntax",
      "command": "python3 -m json.tool {file} > /dev/null 2>&1 || echo 'INVALID: {file}'",
      "loop": true,
      "input_from": "find_json"
    },
    {
      "id": "format",
      "tool": "jq",
      "description": "Pretty-print with sorted keys",
      "command": "jq -S . {file} > {file}.tmp && mv {file}.tmp {file}",
      "loop": true,
      "input_from": "find_json"
    }
  ],
  "bash_oneliner": "find . -name '*.json' -not -path '*/node_modules/*' -exec sh -c 'jq -S . \"$1\" > \"$1.tmp\" && mv \"$1.tmp\" \"$1\"' _ {} \\;",
  "modes": {
    "pretty": "jq -S . {file}",
    "minify": "jq -c . {file}",
    "validate_only": "python3 -m json.tool {file} > /dev/null"
  },
  "environment": {
    "requires": ["jq"],
    "optional": ["python3 (json.tool)", "node"]
  }
}
