1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| import (
"fmt",
"encoding/json",
"git.red-green.com/david/node"
)
/*
{
"kid1": {
"pi": 3.1415,
"degrees": 360
},
"kid2": {
"cat": "meow",
"dog": "woof"
}
}
*/
func main() {
n := node.NewNode()
k1 := n.NewNodeWithName("kid1")
k1.NewNodeWithNameAndData("pi", 3.1415)
k1.NewNodeWithNameAndData("degrees", 360)
k2 := n.NewNodeWithName("kid2")
k2.NewNodeWithNameAndData("cat", "meow")
k2.NewNodeWithNameAndData("dog", "woof")
pay, err := json.MarshalIndent(n, "", " ")
if err != nil {
fmt.Println("Err:", err)
return
}
fmt.Printf("%s\n", pay)
}
|