-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (36 loc) · 778 Bytes
/
main.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
package main
import (
"log"
jsoniter "github.com/json-iterator/go"
"gopkg.in/yaml.v3"
)
func main() {
}
func json2yaml(data []byte) ([]byte, error) {
var tmp map[string]any
err := jsoniter.Unmarshal(data, &tmp)
if err != nil {
log.Println("json unmarshal error:", err)
return nil, err
}
out, err := yaml.Marshal(&tmp)
if err != nil {
log.Println("yaml marshal error:", err)
return nil, err
}
return out, nil
}
func yaml2json(data []byte) ([]byte, error) {
var tmp map[string]any
err := yaml.Unmarshal(data, &tmp)
if err != nil {
log.Println("yaml unmarshal error:", err)
return nil, err
}
out, err := jsoniter.MarshalIndent(&tmp, "", " ")
if err != nil {
log.Println("json marshal error:", err)
return nil, err
}
return out, nil
}