-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.go
69 lines (59 loc) · 1.37 KB
/
json.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
package main
import (
"bytes"
"encoding/json"
"log"
)
type partialItem struct {
UUID string `json:"uuid"`
TemplateUUID string `json:"templateUuid"`
Overview overview `json:"overview"`
}
type completeItem struct {
UUID string `json:"uuid"`
TemplateUUID string `json:"templateUuid"`
Overview overview `json:"overview"`
Details details `json:"details"`
RawJSON string
}
type overview struct {
AdditionalInfo string `json:"ainfo"`
Title string `json:"title"`
URL string `json:"url"`
}
type details struct {
Fields []field `json:"fields"`
Notes string `json:"notesPlain"`
Sections []section `json:"sections"`
}
type field struct {
Name string `json:"name"`
Value string `json:"value"`
}
type section struct {
Name string `json:"name"`
Title string `json:"title"`
Fields []sectionField `json:"fields"`
}
type sectionField struct {
Type string `json:"k"`
Title string `json:"t"`
Value string `json:"v"`
}
func json2list(rawData []byte) (items []partialItem) {
err := json.Unmarshal(rawData, &items)
if err != nil {
log.Fatal(err)
}
return
}
func json2item(rawData []byte) (item completeItem) {
err := json.Unmarshal(rawData, &item)
if err != nil {
log.Fatal(err)
}
var pretty bytes.Buffer
json.Indent(&pretty, rawData, "", " ")
item.RawJSON = pretty.String()
return
}