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.
prettyp/
├── go.mod
├── go.sum
├── prettyp.go
├── prettyp_test.go
└── readme.md
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 (
"github.com/Masum-Osman/prettyp"
"fmt"
)
func main() {
project := struct {
Id int64 `json:"project_id"`
Title string `json:"title"`
Name string `json:"name"`
Budget float64 `json:"budget"`
Active bool `json:"active"`
Tags []string `json:"tags"`
Milestones []int `json:"milestones"`
Metadata map[string]interface{} `json:"metadata"`
NestedStruct struct {
Description string `json:"description"`
Completed bool `json:"completed"`
} `json:"nested_struct"`
}{
Id: 123,
Title: "Test Project",
Name: "Test Name",
Budget: 1000000.50,
Active: true,
Tags: []string{"Go", "JSON", "PrettyPrint"},
Milestones: []int{1, 2, 3, 4},
Metadata: map[string]interface{}{
"created_by": "User123",
"priority": "High",
},
NestedStruct: struct {
Description string `json:"description"`
Completed bool `json:"completed"`
}{
Description: "Nested Struct Description",
Completed: false,
},
}
err := prettyp.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 ./prettyp
- 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.