rejson

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2021 License: MIT Imports: 5 Imported by: 0

README

rejson

Reshape JSON model. Based on gjson .

Github Action Go Report Card codecov

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFieldCannotSet    = errors.New("field cannot set")
	ErrUnexpectJSONValue = errors.New("Unexpect JSON value")
	ErrUnknownFieldType  = errors.New("Unknown field type")
)
View Source
var (
	ErrUnknownTag = errors.New("Unknown tag")
)

Functions

func Unmarshal

func Unmarshal(jsonString string, v interface{}) error

Unmarshal parses the JSON string and stores the result in the value pointed to by v.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL