package main
import (
"encoding/json"
"fmt"
)
type Product struct {
Id string `json:"id"`
Name string `json:"name"`
Price float32 `json:"price"`
Quantity int `json:"quantity"`
Status bool `json:"status"`
}
func main() {
str := `{"id":"p01","name":"name 1","price":2,"quantity":5,"status":true}`
var product Product
json.Unmarshal([]byte(str), &product)
fmt.Println("Product Info")
fmt.Println("id:", product.Id)
fmt.Println("name:", product.Name)
fmt.Println("price:", product.Price)
fmt.Println("quantity:", product.Quantity)
fmt.Println("status:", product.Status)
}
Product Info
id: p01
name: name 1
price: 2
quantity: 5
status: true