diff --git a/check.go b/check.go index d27b50f..87daf54 100644 --- a/check.go +++ b/check.go @@ -9,15 +9,16 @@ import ( // Result of a Check type Result struct { - Failures []Failure // list of any failures in the Check + // list of any failures in the Check + Failures []Failure `json:"failures"` } // Failure of a particular keyword for a path type Failure struct { - Path string - Keyword string - Expected string - Got string + Path string `json:"path"` + Keyword string `json:"keyword"` + Expected string `json:"expected"` + Got string `json:"got"` } // String returns a "pretty" formatting for a Failure diff --git a/cmd/gomtree/main.go b/cmd/gomtree/main.go index 5f05c52..cbc2ff9 100644 --- a/cmd/gomtree/main.go +++ b/cmd/gomtree/main.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "encoding/json" "flag" "fmt" "log" @@ -30,6 +31,14 @@ var formats = map[string]func(*mtree.Result) string{ } return buffer.String() }, + + "json": func(r *mtree.Result) string { + var buffer bytes.Buffer + if err := json.NewEncoder(&buffer).Encode(r); err != nil { + panic(err) + } + return buffer.String() + }, } func main() {