Skip to content

Commit

Permalink
Use json encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
caitlinelfring committed Oct 20, 2020
1 parent c8f1202 commit 9f366d2
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/printer/json.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package printer

import (
"bytes"
"encoding/json"
"fmt"

Expand All @@ -20,10 +21,8 @@ func NewJSON() *JSON {
// It will not be presented as an array of FileResults. You will neeed to
// Split by new line to parse the full output
func (p *JSON) Print(fs *result.FileResults) error {
b, err := json.Marshal(fs)
if err != nil {
return err
}
fmt.Println(string(b))
return nil
var buf bytes.Buffer
err := json.NewEncoder(&buf).Encode(fs)
fmt.Print(buf.String()) // json Encoder already puts a new line in, so no need for Println here
return err
}

0 comments on commit 9f366d2

Please sign in to comment.