An open API service indexing awesome lists of open source software.

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.

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 main

import (
"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! 🚀