You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Yokii908 i've been using your approach, but wondering if there is a way to stop iteration on error? In my case, if I'm processing a large array and encounter an error, i would like to exit and return the error instead of continuing to iterate through a large array. Currently I do
varinnererrerror_, err:=jsonparser.ArrayEach(bytes, func(data []byte, _ jsonparser.ValueType, _int, _error) {
// exit early if an error has already occurredifinnererr!=nil {
return
}
// do heavy processing and set innererr if an error occursiferr:=doHeavyWork(data); err!=nil {
innererr=errreturn
}
}, "path", "to", "large", "array")
if there is a way to simply return the error and stop iteration, it's not obvious to me.
Reacted by Michael Ben-Nes, RH DÆMNT, Gabe Cook and Brian Shih
Activity
Yokii908 commentedon Apr 12, 2018
You can declare an error variable above your ArrayEach block then assign it in your callback so you can check if nil afterwards.
cludden commentedon Aug 6, 2018
@Yokii908 i've been using your approach, but wondering if there is a way to stop iteration on error? In my case, if I'm processing a large array and encounter an error, i would like to exit and return the error instead of continuing to iterate through a large array. Currently I do
if there is a way to simply return the error and stop iteration, it's not obvious to me.
v1.4.0: ArrayEachErr, Escape/SetString, wildcards, JSONPath, GetArray…
buger commentedon Jul 28, 2026
Implemented in v1.4.0 —
ArrayEachErrlets the callback return an error to stop iteration early. See: https://github.com/buger/jsonparser/releases/tag/v1.4.0