Documentation
¶
Overview ¶
Package jsonstruct provides a JSON deserializer for Go structures for Go 1.7+
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var TypeMap map[string]reflect.Type
TypeMap provides a Type registry, mapping type names to reflect Types
Functions ¶
func Decode ¶
Decode one or multiple Go structures from JSON, register and return their Types
Example ¶
package main
import (
"github.com/berlincount/jsonstruct"
"strings"
"github.com/davecgh/go-spew/spew"
)
func main() {
testStructJSON := `
{"struct": "test",
"fields": [
{"name": "TestInt", "type": "int", "tags": "testTag:\"first_field\""},
{"name": "TestString", "type": "string", "tags": "testTag:\"second_field\""}
]}
`
decodedStructs, _ := jsonstruct.Decode(strings.NewReader(testStructJSON))
spewWithoutAddresses := spew.ConfigState{DisablePointerAddresses: true}
spewWithoutAddresses.Dump(decodedStructs)
}
Output: (map[string]reflect.Type) (len=1) { (string) (len=4) "test": (*reflect.rtype)(struct { TestInt int "testTag:\"first_field\""; TestString string "testTag:\"second_field\"" }) }
Types ¶
Click to show internal directories.
Click to hide internal directories.