-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (58 loc) · 1.28 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"github.com/akshaybharambe14/ijson"
)
var dataBytes = []byte(`
[
{
"index": 0,
"friends": [
{
"id": 0,
"name": "Justine Bird"
},
{
"id": 0,
"name": "Justine Bird"
},
{
"id": 1,
"name": "Marianne Rutledge"
}
]
}
]
`)
// var data = []interface{}{
// map[string]interface{}{
// "index": 0,
// "friends": []interface{}{
// map[string]interface{}{
// "id": 0,
// "name": "Justine Bird",
// },
// map[string]interface{}{
// "id": 0,
// "name": "Justine Bird",
// },
// map[string]interface{}{
// "id": 1,
// "name": "Marianne Rutledge",
// },
// },
// },
// }
func main() {
r := ijson.ParseBytes(dataBytes).
GetP("#0.friends.#~name"). // list the friend names for 0th record -
// []interface {}{"Justine Bird", "Justine Bird", "Marianne Rutledge"}
Del("#0"). // delete 0th record
// []interface {}{"Marianne Rutledge", "Justine Bird"}
Set("tom", "#") // append "tom" in the list
// // []interface {}{"Marianne Rutledge", "Justine Bird", "tom"}
fmt.Printf("%#v\n", r.Value())
// output: []interface {}{"Marianne Rutledge", "Justine Bird", "tom"}
// returns error if the data type differs than the type expected by query
fmt.Println(r.Set(1, "name").Error())
}