24 lines
442 B
Go
24 lines
442 B
Go
package jsonprint
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
|
|
"github.com/alecthomas/chroma/quick"
|
|
)
|
|
|
|
func Print(v any) {
|
|
// Marshal your data to pretty JSON
|
|
b, err := json.MarshalIndent(v, "", " ")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Use Chroma to print colored JSON to stdout
|
|
// lexer: "json", style: "monokai", writer: os.Stdout
|
|
err = quick.Highlight(os.Stdout, string(b), "json", "terminal", "solarized")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|