From 1b0416b81bd510bffbd1ecd629a4d74ac8896668 Mon Sep 17 00:00:00 2001 From: Rafik Draoui Date: Sat, 13 Nov 2021 22:42:44 -0400 Subject: [PATCH] Ensure that the Issues key in JSON format is a list This makes the data more consistent and easier to use with other tools. For example, a third-party tool can iterate over `Issues` without having to make a preliminary null check. --- pkg/printers/json.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/printers/json.go b/pkg/printers/json.go index 6ffa996fb0e4..d68b82c2f3bf 100644 --- a/pkg/printers/json.go +++ b/pkg/printers/json.go @@ -30,6 +30,9 @@ func (p JSON) Print(ctx context.Context, issues []result.Issue) error { Issues: issues, Report: p.rd, } + if res.Issues == nil { + res.Issues = []result.Issue{} + } outputJSON, err := json.Marshal(res) if err != nil {