Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 1.43 KB

README.md

File metadata and controls

59 lines (42 loc) · 1.43 KB

rejson

Reshape JSON model. Based on gjson .

Github Action Go Report Card codecov Go.dev

Install

Run go get:

go get -u github.com/sdvcrx/rejson

Usage

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}
}

Performance

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

License

MIT