-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
36 lines (33 loc) · 773 Bytes
/
main.go
File metadata and controls
36 lines (33 loc) · 773 Bytes
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
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"ezpkg.io/errorz"
iterjson "ezpkg.io/iter.json"
)
func main() {
_, file, _, _ := runtime.Caller(0)
data := errorz.Must(os.ReadFile(filepath.Dir(file) + "/../order.json"))
{
// 🥝Example: convert all number ids to string
b := iterjson.NewBuilder("", " ")
for item, err := range iterjson.Parse(data) {
errorz.MustZ(err)
key, _ := item.GetRawPath().Last().ObjectKey()
if strings.HasSuffix(key, "_id") {
id, err0 := item.Token.GetInt()
if err0 == nil {
b.Add(item.Key, strconv.Itoa(id))
continue
}
}
b.Add(item.Key, item.Token)
}
out := errorz.Must(b.Bytes())
fmt.Printf("\n--- convert number id ---\n%s\n----------\n", out)
}
}