Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
encoding/json: some strings aren't marshaled/unmarshaled correctly #9068
go version go1.3.1 darwin/amd64 The following snippet illustrates the problem I'm encountering: http://play.golang.org/p/7qCY_H5pnN Another example: http://play.golang.org/p/5Jt-wqnlNT What happened? If you try to marshal / unmarshal a sha1 hash (byte) cast to a string, you don't get the same string out as you put in. What should have happened instead? Ideally, you should get the same string out as you put in. If that turns out to be impossible for some reason, maybe make the Marshal function return an error for strings it can't handle? Additional You guys probably don't need this, but I tried the following as a sanity check for myself on what it means to cast from byte to string in go: http://play.golang.org/p/9n7GLU9R14
This behaviour, while sometimes annoying, is working as intended and is documented on tip: "String values encode as JSON strings coerced to valid UTF-8, replacing invalid bytes with the Unicode replacement rune." To use random bytes as a JSON string, you need to convert them to hex, for example, modifying your first test case as http://play.golang.org/p/qrpMkJC8Mb .
Status changed to WorkingAsIntended.