@@ -55,10 +55,16 @@ if value, _, err := jsonparser.GetInt(data, "company", "size"); err == nil {
55
55
size = value
56
56
}
57
57
58
- // You can use `ArrayEach` helper to iterate items
58
+ // You can use `ArrayEach` helper to iterate items [item1, item2 .... itemN]
59
59
jsonparser.ArrayEach (data, func (value []byte , dataType jsonparser.ValueType , offset int , err error ) {
60
60
fmt.Println (jsonparser.Get (value, " url" ))
61
- }, " person" , " gravatar" , " avatars" )
61
+ }, " person" , " avatars" )
62
+
63
+ // You can use `ObjectEach` helper to iterate objects { "key1":object1, "key2":object2, .... "keyN":objectN }
64
+ jsonparser.ObjectEach (data, func (key []byte , value []byte , dataType jsonparser.ValueType , offset int ) error {
65
+ fmt.Printf (" Key: '%s '\n Value: '%s '\n Type: %s \n " , string (key), string (value), dataType)
66
+ return nil
67
+ }, " person" , " name" )
62
68
```
63
69
64
70
## Need to speedup your app?
@@ -125,6 +131,20 @@ func ArrayEach(data []byte, cb func(value []byte, dataType jsonparser.ValueType,
125
131
```
126
132
Needed for iterating arrays, accepts a callback function with the same return arguments as `Get`.
127
133
134
+ ### **`ObjectEach`**
135
+ ```go
136
+ func ObjectEach(data []byte, callback func(key []byte, value []byte, dataType ValueType, offset int) error, keys ...string) (err error)
137
+ ```
138
+ Needed for iterating object, accepts a callback function. Example:
139
+ ```go
140
+ var handler func([]byte, []byte, jsonparser.ValueType, int) error
141
+ handler = func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error {
142
+ // do stuff here
143
+ }
144
+ jsonparser.ObjectEach (myJson, handler)
145
+ ```
146
+
147
+
128
148
### ** ` KeyEach ` **
129
149
``` go
130
150
func KeyEach (data []byte , cb func (idx int , value []byte , dataType jsonparser.ValueType , err error ), paths ...[]string )
0 commit comments