Skip to content

Commit 0541194

Browse files
author
Rami.D
committed
Fix AND Update REDAME.md to include ObjectEach(..)
1 parent 054711a commit 0541194

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, off
6161
}, "person", "avatars")
6262

6363
// 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, err error) {
64+
jsonparser.ObjectEach(data, func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error {
6565
fmt.Printf("Key: '%s'\n Value: '%s'\n Type: %s\n", string(key), string(value), dataType)
66+
return nil
6667
}, "person", "name")
6768
```
6869

@@ -130,6 +131,20 @@ func ArrayEach(data []byte, cb func(value []byte, dataType jsonparser.ValueType,
130131
```
131132
Needed for iterating arrays, accepts a callback function with the same return arguments as `Get`.
132133

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+
133148
### **`KeyEach`**
134149
```go
135150
func KeyEach(data []byte, cb func(idx int, value []byte, dataType jsonparser.ValueType, err error), paths ...[]string)

0 commit comments

Comments
 (0)