Repository navigation
Closed
Description
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
- Implement JSON output format for list command
- Preserve existing human-readable table output as default
- Enable automation to extract full environment names without truncation
- Follow the architecture pattern established in Add JSON Output to create Command #349, Add JSON output to provision command #352, Add JSON output to show command #355, and Add JSON output to run command #357
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
jqor 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
JsonViewinsrc/presentation/views/commands/list/views/json_view.rs - Add
#[derive(Serialize)]toEnvironmentListandEnvironmentSummaryDTOs - Update
ListCommandControllerto acceptoutput_formatparameter - Update router to pass
output_formatfromExecutionContext - 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
- Part of EPIC EPIC: Add JSON output format support #348 (Phase 1: JSON Output for High-Value Commands)
- Task 12.5 in project roadmap
- Follows pattern from:
- Add JSON Output to create Command #349 (create command) ✅
- Add JSON output to provision command #352 (provision command) ✅
- Add JSON output to show command #355 (show command) ✅
- Add JSON output to run command #357 (run command) ✅
Metadata
Metadata
Assignees
Labels
No labels
Activity
docs: add issue #359 link to roadmap task 12.5
feat: [#359] add JSON output to list command
refactor: [#359] increase environment name column width from 20 to 50…
docs: [#359] update command documentation with real sample outputs
Merge #360: Add JSON Output to List Command
chore: remove closed issue documentation files