-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.go
69 lines (58 loc) · 1.11 KB
/
hello.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2018 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
import (
"fmt"
"sort"
"github.com/chai2010/jsonmap"
)
func main() {
var jsonMap = jsonmap.JsonMap{
"a": map[string]interface{}{
"sub-a": "value-sub-a",
},
"b": map[string]interface{}{
"sub-b": "value-sub-b",
},
"c": 123,
"d": 3.14,
"e": true,
"x": map[string]interface{}{
"a": map[string]interface{}{
"sub-a": "value-sub-a",
},
"b": map[string]interface{}{
"sub-b": "value-sub-b",
},
"c": 123,
"d": 3.14,
"e": true,
"z": map[string]interface{}{
"zz": "value-zz",
},
},
}
m := jsonMap.ToMapString("/")
var keys []string
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
fmt.Println(k, m[k])
}
// Output:
// /a/sub-a value-sub-a
// /b/sub-b value-sub-b
// /c 123
// /d 3.14
// /e true
// /x/a/sub-a value-sub-a
// /x/b/sub-b value-sub-b
// /x/c 123
// /x/d 3.14
// /x/e true
// /x/z/zz value-zz
}