encoding/json: clearer error message for boolean like prefix in invalid json strings #56332
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
)?go env
OutputWhat did you do?
Json.Unmarshal tries to box a string that starts with a boolean character ('t' or 'f') into a different error compared to a string starting with any other character. This causes the json validation error to be confusing. Can the error be fixed to be similar in both cases (first character invalid) or make the error for attempted boolean parsing to be different ("invalid boolean prefix detected", etc.).
Reproduced here:
https://go.dev/play/p/-AeaDZbeRj1
Code:
In the above, the error showing "invalid character 'e' in literal true" can be updated to state "invalid literal..." for clarity.
What did you expect to see?
"invalid literal true, error in character 'e'"
What did you see instead?
invalid character 'e' in literal true (expecting 'r')
The text was updated successfully, but these errors were encountered: