neatjson makes JSON encoding in Golang clean and simple.
π¨ Flexible Indentation Options: Choose from TAB, spaces (0-4), or custom indentation styles β‘ Error Handling Modes: Must (panic), Soft (log), or Omit (silent) - pick the mode that fits context π Bidirectional Formatting: Format both Go structures and raw JSON data (strings/bytes) π¦ Convenience Wrappers: Auto-generated packages with sensible defaults for rapid development π οΈ Type-Safe API: Clean, chainable interface with compile-time safety
go get github.com/yyle88/neatjsonpackage main
import (
"fmt"
"github.com/yyle88/neatjson/neatjsons"
)
func main() {
// Convert struct to formatted JSON string
data := map[string]any{
"name": "example",
"count": 42,
}
result := neatjsons.S(data)
fmt.Println(result)
}β¬οΈ Source: Source
package main
import (
"fmt"
"github.com/yyle88/neatjson/neatjsons"
)
func main() {
// Format compact JSON bytes to readable string
jsonBytes := []byte(`{"name":"test","age":30,"active":true}`)
result := neatjsons.SxB(jsonBytes)
fmt.Println(result)
}β¬οΈ Source: Source
neatjsons - Must mode:
import "github.com/yyle88/neatjson/neatjsons"
json := neatjsons.S(data) // panic on errorneatjsono - Omit mode:
import "github.com/yyle88/neatjson/neatjsono"
json := neatjsono.S(data) // silent on errorneatjsonz - Soft mode:
import "github.com/yyle88/neatjson/neatjsonz"
json := neatjsonz.S(data) // log on errorTAB indentation (default):
result := neatjson.TAB.Must().S(data)No indentation (compact):
result := neatjson.NOI.Must().S(data)2-space indentation:
result := neatjson.SP2.Must().S(data)4-space indentation:
result := neatjson.SP4.Must().S(data)Must mode - panic on error:
result := neatjson.TAB.Must().S(data)Soft mode - log error and return empty:
result := neatjson.TAB.Soft().S(data)Omit mode - silently return empty:
result := neatjson.TAB.Omit().S(data)String to String:
formatted := neatjson.TAB.Must().SxS(`{"compact":"json"}`)Bytes to Bytes:
formatted := neatjson.SP2.Must().BxB([]byte(`{"raw":"data"}`))Bytes to String:
formatted := neatjson.TAB.Must().SxB(jsonBytes)String to Bytes:
formatted := neatjson.SP4.Must().BxS(jsonString)Go struct to JSON bytes:
type User struct {
Name string `json:"name"`
Mailbox string `json:"mailbox"`
}
user := User{Name: "Alice", Mailbox: "alice@example.com"}
jsonBytes := neatjson.SP4.Must().B(user)Chain with error handling:
result, err := neatjson.TAB.S(complexData)
if err != nil {
// Handle error
}MIT License. See LICENSE.
Contributions are welcome! Report bugs, suggest features, and contribute code:
- π Found a mistake? Open an issue on GitHub with reproduction steps
- π‘ Have a feature idea? Create an issue to discuss the suggestion
- π Documentation confusing? Report it so we can improve
- π Need new features? Share the use cases to help us understand requirements
- β‘ Performance issue? Help us optimize through reporting slow operations
- π§ Configuration problem? Ask questions about complex setups
- π’ Follow project progress? Watch the repo to get new releases and features
- π Success stories? Share how this package improved the workflow
- π¬ Feedback? We welcome suggestions and comments
New code contributions, follow this process:
- Fork: Fork the repo on GitHub (using the webpage UI).
- Clone: Clone the forked project (
git clone https://github.com/yourname/repo-name.git). - Navigate: Navigate to the cloned project (
cd repo-name) - Branch: Create a feature branch (
git checkout -b feature/xxx). - Code: Implement the changes with comprehensive tests
- Testing: (Golang project) Ensure tests pass (
go test ./...) and follow Go code style conventions - Documentation: Update documentation to support client-facing changes and use significant commit messages
- Stage: Stage changes (
git add .) - Commit: Commit changes (
git commit -m "Add feature xxx") ensuring backward compatible code - Push: Push to the branch (
git push origin feature/xxx). - PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.
Please ensure tests pass and include relevant documentation updates.
Welcome to contribute to this project via submitting merge requests and reporting issues.
Project Support:
- β Give GitHub stars if this project helps you
- π€ Share with teammates and (golang) programming friends
- π Write tech blogs about development tools and workflows - we provide content writing support
- π Join the ecosystem - committed to supporting open source and the (golang) development scene
Have Fun Coding with this package! πππ