Skip to content

ArrayEach can not return error #176

Description

@dunixd

jsonparser/parser.go

Lines 943 to 957 in bf1c66b

if e != nil {
return offset, e
}
if o == 0 {
break
}
if t != NotExist {
cb(v, t, offset+o-len(v), e)
}
if e != nil {
break
}

how to indicate that cb return an error for ArrayEach, like ObjectEach do.

jsonparser/parser.go

Lines 1053 to 1060 in bf1c66b

// Step 3: find the associated value, then invoke the callback
if value, valueType, off, err := Get(data[offset:]); err != nil {
return err
} else if err := callback(key, value, valueType, offset+off); err != nil { // Invoke the callback here!
return err
} else {
offset += off
}

Activity

  1. stephane-moreau commented on Oct 13, 2020

    @stephane-moreau

    I had the same issue, willing to fail fast on some JSON parsing, I've put together a PR #214 feel free to comment and review

  2. buger commented on Jul 28, 2026

    @buger
    Owner

    Implemented in v1.4.0 — ArrayEachErr(data, func(value []byte, vt ValueType, offset int, err error) error { return myErr }, keys...). See: https://github.com/buger/jsonparser/releases/tag/v1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions