github.com/enetx/g@v1.0.80/examples/json.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/enetx/g" 7 ) 8 9 func main() { 10 type response struct { 11 Page g.Int `json:"page"` 12 Fruits g.Slice[string] `json:"fruits"` 13 } 14 15 res := response{Page: 1, Fruits: g.SliceOf("apple", "peach", "pear")} 16 17 s := g.NewString("").Enc().JSON(res).Unwrap().Append("\n").Print() 18 19 var res2 response 20 21 s.Dec().JSON(&res2) 22 fmt.Println(res.Page, res.Fruits.Get(-2)) 23 }