This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nexcloud-deck-import-trello-json.go
87 lines (74 loc) · 2.37 KB
/
nexcloud-deck-import-trello-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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"os"
)
// https://tutorialedge.net/golang/parsing-json-with-golang/
// https://www.sohamkamani.com/blog/2017/10/18/parsing-json-in-golang/
func main() {
jsonFile, err := os.Open("trello-board-example.json")
if err != nil {
fmt.Println(err)
}
defer jsonFile.Close()
// Read JSON as byte array
jsonBytes, _ := ioutil.ReadAll(jsonFile)
// Unmarshal JSON bytes as map of strings
var result map[string]interface{}
json.Unmarshal(jsonBytes, &result)
trelloBoardID := result["id"].(string)
trelloBoardName := result["name"].(string)
trelloCards := result["cards"].([]interface{})
trelloLists := result["lists"].([]interface{})
trelloChecklists := result["checklists"].([]interface{})
fmt.Println("Board Name:", trelloBoardName)
fmt.Println("Board ID:", trelloBoardID)
fmt.Println()
for key, value := range trelloLists {
data := value.(map[string]interface{})
id := data["id"].(string)
name := data["name"].(string)
fmt.Println("List number", key)
fmt.Println("- id: ", id)
fmt.Println("- name:", name)
}
fmt.Println()
for key, value := range trelloCards {
data := value.(map[string]interface{})
id := data["id"].(string)
name := data["name"].(string)
desc := data["desc"].(string)
parentBoardID := data["idBoard"].(string)
parentListID := data["idList"].(string)
fmt.Println("Card number ", key)
fmt.Println("- id: ", id)
fmt.Println("- name:", name)
fmt.Printf( "- desc: '%s'\n", url.QueryEscape(desc))
fmt.Println("- parent board id:", parentBoardID)
fmt.Println("- parent list id: ", parentListID)
}
fmt.Println()
for key, value := range trelloChecklists {
data := value.(map[string]interface{})
id := data["id"].(string)
name := data["name"].(string)
parentBoardID := data["idBoard"].(string)
parentCardID := data["idCard"].(string)
checkItems := data["checkItems"].([]interface {})
fmt.Println("Checklist number", key)
fmt.Println("- id: ", id)
fmt.Println("- name:", name)
fmt.Println("- parent board id:", parentBoardID)
fmt.Println("- parent card id: ", parentCardID)
fmt.Println("- check items:", len(checkItems))
for key, value := range checkItems {
data := value.(map[string]interface{})
name := data["name"].(string)
state := data["state"].(string)
fmt.Printf( " %2d: %-10s - '%s'\n", key, state, name)
}
}
}