10 examples of 'golang json unmarshal' in Go

Every line of 'golang json unmarshal' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
41func JSONUnmarshal(data []byte, v interface{}) error {
42 return json.Unmarshal(data, v)
43}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

91func (et *EventType) UnmarshalJSON(data []byte) error {
92 switch string(data) {
93 case "\"added\"":
94 *et = EventAdded
95 case "\"removed\"":
96 *et = EventRemoved
97 default:
98 fmt.Println(string(data))
99 return errors.New("bad event type")
100 }
101
102 return nil
103}
633func (pbi *ProcBindInfo) UnmarshalJSON(data []byte) error {
634 err := defaultProcBindInfoHandle.UJSON(data, pbi)
635 if err != nil {
636 return err
637 }
638 return nil
639}
56func (p *TxS) UnmarshalJSON(data []byte) (err error) {
57 parsed, err := txMapper.FromJSON(data)
58 if err == nil {
59 p.Tx = parsed.(Tx)
60 }
61 return
62}
40func UnmarshalFromJSON(data []byte) (*JsonRows, error) {
41 var jRows JsonRows
42 err := json.Unmarshal(data, &jRows)
43
44 if err != nil {
45 return nil, err
46 }
47
48 return &jRows, nil
49}
48func (b *Conditional) UnmarshalJSON(jsonData []byte) error {
49 jsonString := string(jsonData)
50 jsonBool, err := strconv.ParseBool(jsonString)
51 if err != nil && jsonString != "null" {
52 return err
53 }
54
55 if jsonString == "" || jsonString == "null" {
56 *b = DefaultEnabled
57 } else if jsonBool {
58 *b = ExplicitlyEnabled
59 } else {
60 *b = ExplicitlyDisabled
61 }
62
63 return nil
64}
1232func (i *ComponentsSecuritySchemesAZAZ09) UnmarshalJSON(data []byte) error {
1233 mayUnmarshal := []interface{}{&i.Reference, &i.SecurityScheme}
1234 err := unionMap{
1235 mayUnmarshal: mayUnmarshal,
1236 jsonData: data,
1237 }.unmarshal()
1238 if mayUnmarshal[0] == nil {
1239 i.Reference = nil
1240 }
1241 if mayUnmarshal[1] == nil {
1242 i.SecurityScheme = nil
1243 }
1244
1245 return err
1246}
25func (m *SiteSetup) UnmarshalJSON(raw []byte) error {
26 // AO0
27 var aO0 Site
28 if err := swag.ReadJSON(raw, &aO0); err != nil {
29 return err
30 }
31 m.Site = aO0
32
33 // AO1
34 var dataAO1 struct {
35 Repo *RepoInfo `json:"repo,omitempty"`
36 }
37 if err := swag.ReadJSON(raw, &dataAO1); err != nil {
38 return err
39 }
40
41 m.Repo = dataAO1.Repo
42
43 return nil
44}
26func (m *V1PlatformPagedListPlatformsItemsCPUArchitectureAllOf1AllOf1) UnmarshalJSON(raw []byte) error {
27 // AO0
28 var aO0 V1PlatformPagedListPlatformsItemsCPUArchitectureAllOf1AllOf1AllOf0
29 if err := swag.ReadJSON(raw, &aO0); err != nil {
30 return err
31 }
32 m.V1PlatformPagedListPlatformsItemsCPUArchitectureAllOf1AllOf1AllOf0 = aO0
33
34 // AO1
35 var aO1 V1PlatformPagedListPlatformsItemsCPUArchitectureAllOf1AllOf1AllOf1
36 if err := swag.ReadJSON(raw, &aO1); err != nil {
37 return err
38 }
39 m.V1PlatformPagedListPlatformsItemsCPUArchitectureAllOf1AllOf1AllOf1 = aO1
40
41 return nil
42}
21func (m *PVMInstanceAddress) UnmarshalJSON(raw []byte) error {
22 // AO0
23 var aO0 PVMInstanceNetwork
24 if err := swag.ReadJSON(raw, &aO0); err != nil {
25 return err
26 }
27 m.PVMInstanceNetwork = aO0
28
29 return nil
30}

Related snippets