diff --git a/.gitignore b/.gitignore index 026ca0fab..4c23fb948 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ coverage/ repomix-output.txt repomix-output.xml repomix-output.md +repomix-output.json # ESLint cache .eslintcache diff --git a/README.md b/README.md index 35d26a134..ecb68aa9c 100644 --- a/README.md +++ b/README.md @@ -478,6 +478,76 @@ src/ This format provides a clean, readable structure that is both human-friendly and easily parseable by AI systems. +#### JSON Format + +To generate output in JSON format, use the `--style json` option: + +```bash +repomix --style json +``` + +The JSON format structures the content as a hierarchical JSON object with camelCase property names: + +```json +{ + "fileSummary": { + "generationHeader": "This file is a merged representation of the entire codebase, combined into a single document by Repomix.", + "purpose": "This file contains a packed representation of the entire repository's contents...", + "fileFormat": "The content is organized as follows...", + "usageGuidelines": "- This file should be treated as read-only...", + "notes": "- Some files may have been excluded based on .gitignore rules..." + }, + "userProvidedHeader": "Custom header text if specified", + "directoryStructure": "src/\n cli/\n cliOutput.ts\n index.ts\n config/\n configLoader.ts", + "files": { + "src/index.js": "// File contents here", + "src/utils.js": "// File contents here" + }, + "instruction": "Custom instructions from instructionFilePath" +} +``` + +This format is ideal for: +- **Programmatic processing**: Easy to parse and manipulate with JSON libraries +- **API integration**: Direct consumption by web services and applications +- **AI tool compatibility**: Structured format for machine learning and AI systems +- **Data analysis**: Straightforward extraction of specific information using tools like `jq` + +##### Working with JSON Output Using `jq` + +The JSON format makes it easy to extract specific information programmatically: + +```bash +# List all file paths +cat repomix-output.json | jq -r '.files | keys[]' + +# Count total number of files +cat repomix-output.json | jq '.files | keys | length' + +# Extract specific file content +cat repomix-output.json | jq -r '.files["README.md"]' +cat repomix-output.json | jq -r '.files["src/index.js"]' + +# Find files by extension +cat repomix-output.json | jq -r '.files | keys[] | select(endswith(".ts"))' + +# Get files containing specific text +cat repomix-output.json | jq -r '.files | to_entries[] | select(.value | contains("function")) | .key' + +# Extract directory structure +cat repomix-output.json | jq -r '.directoryStructure' + +# Get file summary information +cat repomix-output.json | jq '.fileSummary.purpose' +cat repomix-output.json | jq -r '.fileSummary.generationHeader' + +# Extract user-provided header (if exists) +cat repomix-output.json | jq -r '.userProvidedHeader // "No header provided"' + +# Create a file list with sizes +cat repomix-output.json | jq -r '.files | to_entries[] | "\(.key): \(.value | length) characters"' +``` + #### Plain Text Format To generate output in plain text format, use the `--style plain` option: @@ -544,7 +614,7 @@ Instruction #### Repomix Output Options - `-o, --output `: Output file path (default: repomix-output.xml, use "-" for stdout) -- `--style