Skip to content

Commit fb2dfce

Browse files
Format and colorize JSON output
1 parent 038cd71 commit fb2dfce

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cmd/jsonpath/eval.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/bhmj/jsonslice"
99
"github.com/charmbracelet/log"
1010
"github.com/spf13/cobra"
11+
"github.com/tidwall/pretty"
1112
)
1213

1314
func newEvalCommand() *cobra.Command {
@@ -41,7 +42,14 @@ func newEvalCommand() *cobra.Command {
4142
return err
4243
}
4344

44-
fmt.Print(string(result))
45+
// Format the JSON
46+
formattedJSON := pretty.Pretty([]byte(result))
47+
48+
// Color the JSON
49+
coloredJSON := pretty.Color(formattedJSON, nil)
50+
51+
// Print formatted and colored JSON
52+
fmt.Print(string(coloredJSON))
4553

4654
return nil
4755

0 commit comments

Comments
 (0)