Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: parser can't handle Byte Order Mark #12254

Closed
Flokey82 opened this issue Aug 21, 2015 · 1 comment

Comments

Projects
None yet
3 participants
@Flokey82
Copy link

commented Aug 21, 2015

Trying to parse a json file that contains a byte order mark results in an error
[]byte{0xEF, 0xBB, 0xBF} (the first 3 bytes of the file)

// LocaleMessage represents a single translation for an entry in the localization map.
type LocaleMessage struct {
Message string json:"message"
Description string json:"description"
}

lj := make(map[string]LocaleMessage)
if err := json.Unmarshal(data, &lj); err != nil {
return nil, err
}

The error message returned while trying to unmarshal:
invalid character 'ï' looking for beginning of value

The json file in question is from a chrome extension that ships with ChromeOS (I seem not to be able to attach the json file -> unsupported file type).

When I trim the first 3 bytes, it parses just fine.

@bradfitz

This comment has been minimized.

Copy link
Member

commented Aug 21, 2015

This has come up before. We don't like BOMs. And JSON shouldn't have them anyway. (XML might have a slightly better excuse)

You should just strip them yourself. You can write a function or new io.Reader wrapper to do it. They probably already exist on godoc.org.

@bradfitz bradfitz closed this Aug 21, 2015

@mikioh mikioh changed the title JSON parser can't handle Byte Order Mark encoding/json: parser can't handle Byte Order Mark Aug 22, 2015

@golang golang locked and limited conversation to collaborators Aug 22, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.