Overview
Add machine-readable JSON output format (--output-format json) to the list command. This enables automation workflows and AI agents to programmatically extract environment information (full names, states, providers, timestamps) without parsing human-readable text tables that may truncate long names.
Parent Epic: #348 - Add JSON output format support
Roadmap: Section 12.5
Specification: docs/issues/359-add-json-output-to-list-command.md
Goals
Rationale
Why JSON Output for List?
The table format truncates long environment names to fit the terminal width, making it difficult to:
- Parse environment names programmatically
- Disambiguate environments with long names
- Extract complete environment information for automation workflows
JSON output provides:
- Full environment names without truncation
- Structured data for easy parsing with
jq or programming languages
- Complete state and timestamp information for each environment
- Failed environment details for error handling
Implementation Approach
Following the established Strategy Pattern from #349, #352, #355, and #357:
- Create
JsonView in src/presentation/views/commands/list/views/json_view.rs
- Add
#[derive(Serialize)] to EnvironmentList and EnvironmentSummary DTOs
- Update
ListCommandController to accept output_format parameter
- Update router to pass
output_format from ExecutionContext
- Add comprehensive unit tests
- Update user documentation with JSON examples and automation use cases
Example JSON Output
{
"environments": [
{
"name": "production-high-availability-tracker",
"state": "Running",
"provider": "Hetzner",
"created_at": "2026-02-14T16:45:00Z"
},
{
"name": "staging-environment",
"state": "Provisioned",
"provider": "LXD",
"created_at": "2026-02-10T09:15:00Z"
}
],
"total_count": 2,
"failed_environments": [],
"data_directory": "/path/to/project/data"
}
Automation Use Cases
# Extract all environment names
torrust-tracker-deployer list -o json | jq -r '.environments[].name'
# Filter by state
torrust-tracker-deployer list -o json | jq -r '.environments[] | select(.state == "Running") | .name'
# Count by provider
torrust-tracker-deployer list -o json | jq '.environments | group_by(.provider) | map({provider: .[0].provider, count: length})'
Success Criteria
- ✅ JSON output implemented following Strategy Pattern
- ✅ Full environment names provided without truncation
- ✅ All tests passing (unit + integration)
- ✅ All linters passing
- ✅ Documentation updated with JSON examples and automation use cases
- ✅ Backward compatible (text output unchanged)
Related Issues
Overview
Add machine-readable JSON output format (
--output-format json) to thelistcommand. This enables automation workflows and AI agents to programmatically extract environment information (full names, states, providers, timestamps) without parsing human-readable text tables that may truncate long names.Parent Epic: #348 - Add JSON output format support
Roadmap: Section 12.5
Specification:
docs/issues/359-add-json-output-to-list-command.mdGoals
Rationale
Why JSON Output for List?
The table format truncates long environment names to fit the terminal width, making it difficult to:
JSON output provides:
jqor programming languagesImplementation Approach
Following the established Strategy Pattern from #349, #352, #355, and #357:
JsonViewinsrc/presentation/views/commands/list/views/json_view.rs#[derive(Serialize)]toEnvironmentListandEnvironmentSummaryDTOsListCommandControllerto acceptoutput_formatparameteroutput_formatfromExecutionContextExample JSON Output
{ "environments": [ { "name": "production-high-availability-tracker", "state": "Running", "provider": "Hetzner", "created_at": "2026-02-14T16:45:00Z" }, { "name": "staging-environment", "state": "Provisioned", "provider": "LXD", "created_at": "2026-02-10T09:15:00Z" } ], "total_count": 2, "failed_environments": [], "data_directory": "/path/to/project/data" }Automation Use Cases
Success Criteria
Related Issues