MCPcopy Create free account
hub / github.com/francoispqt/gojay / ExampleDecodeObjectFunc

Function ExampleDecodeObjectFunc

decode_example_test.go:51–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49}
50
51func ExampleDecodeObjectFunc() {
52 reader := strings.NewReader(`{
53 "name": "John Doe",
54 "email": "john.doe@email.com"
55 }`)
56 dec := gojay.NewDecoder(reader)
57
58 user := struct {
59 name string
60 email string
61 }{}
62 dec.DecodeObject(gojay.DecodeObjectFunc(func(dec *gojay.Decoder, k string) error {
63 switch k {
64 case "name":
65 return dec.String(&user.name)
66 case "email":
67 return dec.String(&user.email)
68 }
69 return nil
70 }))
71
72 fmt.Printf("User\nname: %s\nemail: %s", user.name, user.email)
73
74 // Output:
75 // User
76 // name: John Doe
77 // email: john.doe@email.com
78}
79
80func ExampleDecodeArrayFunc() {
81 reader := strings.NewReader(`[

Callers

nothing calls this directly

Calls 4

DecodeObjectMethod · 0.95
StringMethod · 0.95
NewDecoderFunction · 0.92
DecodeObjectFuncFuncType · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…