encoding/json: show nested fields path if DisallowUnknownFields leads to an error #58649
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Hello, Go community!
Problem
I tried to utilize the
DisallowUnknownFields
option forjson.Decoder
and faced a problem. It is not possible get the path of the problematic field from the error.Example:
The structure
and the following config
on decoding will throw an error
json: unknown field "unknown_token"
, yet it is not clear exactly which field caused it.https://go.dev/play/p/zzLCOBn3AI8
If the config is a little, it is fine to find the field, but it is not suitable to validate cumbersome configs.
Proposal
Decoder already has all the info. The only thing left is to return it to a user.
The following block
go/src/encoding/json/decode.go
Lines 747 to 749 in 06b6759
should be rewritten like this
or (to avoid Join)
The text was updated successfully, but these errors were encountered: