File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ func main() {
2020 app .Author = ""
2121 app .Email = ""
2222 app .Flags = []cli.Flag {
23+ cli.BoolFlag {
24+ Name : "compact, c" ,
25+ Usage : "Produce compact JSON output that omits nonessential whitespace." ,
26+ },
2327 cli.StringFlag {
2428 Name : "filename, f" ,
2529 Usage : "Read input JSON from a file instead of stdin." ,
@@ -111,7 +115,12 @@ func runMain(c *cli.Context) int {
111115 if c .Bool ("unquoted" ) && isString {
112116 os .Stdout .WriteString (converted )
113117 } else {
114- toJSON , err := json .MarshalIndent (result , "" , " " )
118+ var toJSON []byte
119+ if c .Bool ("compact" ) {
120+ toJSON , err = json .Marshal (result )
121+ } else {
122+ toJSON , err = json .MarshalIndent (result , "" , " " )
123+ }
115124 if err != nil {
116125 errMsg ("Error marshalling result to JSON: %s\n " , err )
117126 return 3
You can’t perform that action at this time.
0 commit comments