Treeson is a command-line tool that converts directory structures and GitHub repositories into JSON format. Perfect for documentation, analysis, and tooling purposes.
- Directory to JSON: Convert local directory structures to structured JSON
- GitHub Repository Support: Fetch and convert GitHub repository structures
- Smart Filtering: Built-in ignore patterns for common files/folders
- Highly Configurable: Custom ignore patterns, depth limits, and hidden file handling
- Multiple Output Options: stdout, file output, compact or pretty-printed JSON
- Fast and Lightweight: Minimal dependencies, efficient processing
To install as a global tool:
uv tool install git+https://github.com/SergioBonatto/treeson.gitTo add as a dependency in another project:
uv add git+https://github.com/SergioBonatto/treeson.gitgit clone https://github.com/SergioBonatto/treeson.git
cd treeson
uv synctreesontreeson /path/to/directorytreeson https://github.com/user/repositorytreeson . --output structure.jsontreeson [TARGET] [OPTIONS]
TARGET: Directory path or GitHub URL (default: current directory)
| Option | Short | Description |
|---|---|---|
--ignore PATTERN |
-i |
Additional files/folders to ignore (can be used multiple times) |
--branch NAME |
-b |
GitHub branch name (default: main) |
--include-hidden |
-H |
Include hidden files and directories |
--max-depth N |
-d |
Maximum directory depth to traverse |
--output FILE |
-o |
Write output to file instead of stdout |
--compact |
-c |
Output compact JSON (no indentation) |
--pretty |
-p |
Pretty-printed JSON with system-native syntax highlighting |
--version |
-v |
Show version and exit |
The tool generates a JSON structure where:
- Directories are represented as objects with nested structure
- Files are listed in a
"files"array within each directory - The structure preserves the hierarchical organization
Using treeson --pretty will output formatted JSON with syntax highlighting that respects your terminal's color theme:
{
"files": ["main.py", "README.md"],
"src": {
"files": ["__init__.py", "utils.py"],
"models": {
"files": ["user.py", "base.py"]
}
},
"tests": {
"files": ["test_main.py"]
}
}- Python 3.8+
requestslibrary (included as dependency)pygmentslibrary (for syntax highlighting)
from treeson import dir_to_json, TreesonConfig
from pathlib import Path
# Custom configuration
config = TreesonConfig(
ignores={"temp", "logs", "*.tmp"},
include_hidden=True,
max_depth=5
)
# Convert directory
result = dir_to_json(Path("/path/to/dir"), config)
print(result)from treeson import github_repo_to_json, TreesonConfig
# Convert GitHub repository
config = TreesonConfig(ignores={"docs", "examples"})
result = github_repo_to_json(
"https://github.com/user/repo",
config,
branch="main"
)
print(result)- Python 3.8+
requestslibrary (included as dependency)
We recommend using uv for development:
git clone https://github.com/SergioBonatto/treeson.git
cd treeson
uv syncuv run pytestuv run black treeson/
uv run isort treeson/Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Architectural Refactor: Separated core logic from CLI interface.
- Improved Package Structure: Better programmatic API access via
__init__.py. - Enhanced Hygiene: Improved
.gitignoreand removed redundantmain.py. - Modern Tooling: Full support for
uvand dynamic versioning.
- Initial release
- Basic directory to JSON conversion
- GitHub repository support
- CLI interface with comprehensive options
- Smart ignore patterns
Made with care by Sergio Bonatto