forked from teambition/json-mask-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
43 lines (38 loc) · 838 Bytes
/
example_test.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
package jsonmask_test
import (
"fmt"
jsonmask "github.com/teambition/json-mask-go"
)
func Example_mask() {
doc := `
{
"kind": "demo",
"items": [
{
"title": "First title",
"comment": "First comment.",
"characteristics": {
"length": "short",
"accuracy": "high",
"followers": ["Jo", "Will"]
},
"status": "active"
},
{
"title": "Second title",
"comment": "Second comment.",
"characteristics": {
"length": "long",
"accuracy": "medium",
"followers": [ ]
},
"status": "pending"
}
]
}
`
result, _ := jsonmask.Mask([]byte(doc), "kind,items(title,characteristics/length)")
fmt.Println(string(result))
// Output:
// {"items":[{"characteristics":{"length":"short"},"title":"First title"},{"characteristics":{"length":"long"},"title":"Second title"}],"kind":"demo"}
}