From e788757b32774241db84ee317ea09dbec625c22b Mon Sep 17 00:00:00 2001 From: Rafik Draoui Date: Sun, 14 Nov 2021 18:33:19 -0400 Subject: [PATCH] Ensure that the Issues key in JSON format is a list (#2358) 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 {