Reshape JSON model. Based on gjson .
Run go get
:
go get -u github.com/sdvcrx/rejson
package main
import (
"log"
"github.com/sdvcrx/rejson"
)
type User struct {
Name string `rejson:"data.name"`
}
func main() {
jsonString := `{
"code":0,
"msg": null,
"data":{"name":"John"}
}`
u := User{}
rejson.Unmarshal(jsonString, &u)
log.Printf("%#v", u)
// u => User{Name:John}
}
Benchmark cases: bench_test.go
BenchmarkUnmarshalReJSON-4 818850 1443 ns/op 72 B/op 4 allocs/op
BenchmarkUnmarshalGJSONGet-4 1512412 798 ns/op 0 B/op 0 allocs/op
BenchmarkUnmarshalEncodingJSON-4 312958 3785 ns/op 464 B/op 11 allocs/op
MIT