encoding/json: include property name for marshal errors #25153
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
When encountering an error using
json.Marshal()
(and related functions) the error returned gives no indication where the error was encountered. The only included metadata is about the type of the value that was being encoded, but that is usually insufficient to narrow down problems without the original input value. (which may not always be at hand)What is being proposed?
The proposal would be to add the property name for marshal errors (using dot notation to signify hierarchy). For example:
would be updated to be more specific:
and in the case of a more complex/nested data structure:
Why is this useful?
I use Go to do a lot of data processing, which is generally from 3rd-parties (aka: customers) so the structure of data is not usually known ahead of time, not to mention weird values being sent due to programming errors and a host of other problems.
Last week, I encountered the first error message above and needed to do some extra work just to determine which property was causing the error, when the encoder should be able to communicate that to the caller.
The text was updated successfully, but these errors were encountered: