From f1b25cee68c8e107df359828b17c7fcef5a25486 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Fri, 21 Nov 2025 01:56:56 +0100 Subject: [PATCH] fix(print-env): ensure valid JSON output for empty results Signed-off-by: Dominik Schmidt --- pkg/app/print_env.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/app/print_env.go b/pkg/app/print_env.go index 138c1300..10effe19 100644 --- a/pkg/app/print_env.go +++ b/pkg/app/print_env.go @@ -11,6 +11,11 @@ import ( func (a *App) PrintEnv(c PrintEnvConfigProvider) error { docCount := 0 + // Open JSON array if needed + if c.Output() == "json" { + fmt.Println("[") + } + err := a.ForEachState(func(run *Run) (_ bool, errs []error) { st := run.state @@ -43,8 +48,6 @@ func (a *App) PrintEnv(c PrintEnvConfigProvider) error { // For JSON, print array of documents if docCount > 0 { fmt.Println(",") - } else { - fmt.Println("[") } outputBytes, err = json.MarshalIndent(output, " ", " ") if err != nil { @@ -71,7 +74,7 @@ func (a *App) PrintEnv(c PrintEnvConfigProvider) error { }, false) // Close JSON array - if c.Output() == "json" && docCount > 0 { + if c.Output() == "json" { fmt.Println() fmt.Println("]") }