On Mon, Feb 6, 2023 at 4:50 PM 'Axel Wagner' via golang-nuts <[email protected]> wrote: > > The best method I've found is to wrap the input reader in something that > keeps track of lines. You can then type-assert the errors to one of the > exported error types in the json package to get the offset the error occured > and translate it into line numbers using your wrapper. > I have a package for such a wrapper here: https://pkg.go.dev/gonih.org/lines > though it's not particularly well tested. > > On Tue, Feb 7, 2023 at 12:22 AM dave <[email protected]> wrote: >> >> I'm getting the error >> >> panic: json: cannot unmarshal string into Go value of type >> map[string]*json.RawMessage but it does not tell me which line or section of >> my json is causing the issue. How can I see this?
Note that it probably not JSON that is calling panic. You are probably taking the error returned by JSON and passing it to panic. That error value that JSON returned actually contains the exact position of the error. It's just not included in the string returned by the Error method. You can get the position by writing code like err.(*json.UnmarshalTypeError).Offset. See https://pkg.go.dev/encoding/json#UnmarshalTypeError . Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcV76Wk%3DQonevi27bAahU-OP0Pi3GE9zjKA2pb6ico8DGw%40mail.gmail.com.
