-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample.go
More file actions
46 lines (42 loc) · 886 Bytes
/
sample.go
File metadata and controls
46 lines (42 loc) · 886 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
37
38
39
40
41
42
43
44
45
46
package main
import (
"errors"
"fmt"
"github.com/swaraj1802/GoJSON/gojson"
)
func main() {
jsonParsed, err := gojson.ParseJSON([]byte(`{
"ok": true,
"channel": "C1H9RESGL",
"ts": "1503435956.000247",
"message": {
"text": "Here's a message for you",
"username": "ecto1",
"bot_id": "B19LU7CSY",
"attachments": [
{
"text": "This is an attachment",
"id": 1,
"fallback": "This is an attachment's fallback"
},
{
"text": "This is an attachment2",
"id": 2,
"fallback": "This is an attachment's fallback2"
}
],
"type": "message",
"subtype": "bot_message",
"ts": "1503435956.000247"
}
}`))
if err != nil {
panic(err)
}
value, ok := jsonParsed.Search("message", "attachments", "*", "id")
if ok != nil {
panic(errors.New("Element doesn't exist"))
}
output := value.JSONData()
fmt.Println(output)
}