This project provides a utility for pretty-printing JSON with color-coded output. The utility is designed to print keys in blue and values in red, making it easier to read and debug JSON data.
go get github.com/Masum-Osman/prettyp
To use the PrettyPrint function in your Go project, import the package:
import "github.com/Masum-Osman/prettyp"
Here’s an example of how to use the PrettyPrint function:
package main
import (
p "github.com/Masum-Osman/prettyp"
"fmt"
)
func main() {
cat := struct {
Id string `json:"id"`
Name string `json:"name"`
Breed string `json:"breed"`
Age int `json:"age"`
IsIndoor bool `json:"is_indoor"`
WeightKg float64 `json:"weight_kg"`
FavoriteFoods []string `json:"favorite_foods"`
AdoptedAt time.Time `json:"adopted_at"`
Owner Owner `json:"owner"`
}{
Id: "673dcdb47484940c3f9fd08c",
Name: "Whiskers",
Breed: "British Shorthair",
Age: 3,
IsIndoor: true,
WeightKg: 4.2,
FavoriteFoods: []string{"Tuna", "Salmon", "Chicken"},
AdoptedAt: time.Now(),
Owner: Owner{
Name: "Owner",
Email: "[email protected]",
},
}
err := p.PrettyPrint(project)
if err != nil {
fmt.Println("Error:", err)
}
}
To run the example, use the following command:
go run main.go
To run the tests for the PrettyPrint function, use the following command:
go test
- Fork the repository.
- Create your feature branch (
git checkout -b feature/fooBar
). - Commit your changes (
git commit -am 'Add some fooBar'
). - Push to the branch (
git push origin feature/fooBar
). - Create a new Pull Request.
- Inspired by the need for better JSON readability in Go projects.