MCPcopy Create free account
hub / github.com/segmentio/encoding / ExampleMarshal

Function ExampleMarshal

json/golang_example_test.go:17–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func ExampleMarshal() {
18 type ColorGroup struct {
19 ID int
20 Name string
21 Colors []string
22 }
23 group := ColorGroup{
24 ID: 1,
25 Name: "Reds",
26 Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},
27 }
28 b, err := json.Marshal(group)
29 if err != nil {
30 fmt.Println("error:", err)
31 }
32 os.Stdout.Write(b)
33 // Output:
34 // {"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]}
35}
36
37func ExampleUnmarshal() {
38 jsonBlob := []byte(`[

Callers

nothing calls this directly

Calls 2

WriteMethod · 0.80
MarshalMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…