https://github.com/michaelwp/gojson
GoJsonStruct is a lightweight library designed to easily convert Go structs to JSON and vice versa. It provides simple methods to serialize and deserialize JSON data.
https://github.com/michaelwp/gojson
go json struct
Last synced: 3 months ago
JSON representation
GoJsonStruct is a lightweight library designed to easily convert Go structs to JSON and vice versa. It provides simple methods to serialize and deserialize JSON data.
- Host: GitHub
- URL: https://github.com/michaelwp/gojson
- Owner: michaelwp
- Created: 2025-03-27T09:35:58.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-03-28T04:06:29.000Z (3 months ago)
- Last Synced: 2025-03-28T05:19:23.512Z (3 months ago)
- Topics: go, json, struct
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GoJson - Simple JSON Converter for Go
GoJson is a lightweight library designed to easily convert Go structs to JSON and vice versa. It provides simple methods to serialize and deserialize JSON data.
## 🚀 Features
- **Convert struct to JSON** (`ToJSON`)
- **Convert struct to pretty JSON** (`ToJSONPretty`)
- **Convert JSON to struct** (`ToStruct`)## 📥 Installation
To install the package, run:
```sh
go get github.com/michaelwp/goJson/v2
```## 📌 Usage
### Initialize the JSON Converter
```go
package mainimport (
"fmt"
"github.com/michaelwp/goJson/v2"
)func main() {
goJSON := gojson.NewGoJSON()type User struct {
Name string `json:"name"`
Age int `json:"age"`
Email string `json:"email"`
}user := User{Name: "Alice", Age: 30, Email: "[email protected]"}
// Convert struct to JSON
jsonStr := goJSON.ToJSON(user)
fmt.Println(jsonStr) // Output: {"name":"Alice","age":30,"email":"[email protected]"}// Convert struct to pretty JSON
jsonPretty := goJSON.ToJSONPretty(user)
fmt.Println(jsonPretty)// Convert json back to struct
var userStruct User
err := goJSON.ToStruct(jsonStr, &userStruct)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println(userStruct) // Output: {Alice 30 [email protected]}
}
}
```## 🏆 Why GoJsonStruct?
✅ Simple and easy-to-use API
✅ Supports pretty JSON formatting
✅ Minimal dependencies
✅ Improves Go JSON handling efficiency## 📢 Contributing
Contributions are welcome! Feel free to submit pull requests or open issues.
---
Enjoy coding with **GoJson** – because working with JSON in Go should be effortless! 🚀