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: Invalid json is parsed ok #21227

cassiobotaro opened this issue Jul 31, 2017 · 2 comments

encoding/json: Invalid json is parsed ok #21227

cassiobotaro opened this issue Jul 31, 2017 · 2 comments


Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?


What operating system and processor architecture are you using (go env)?

GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/cassiobotaro/go" GORACE="" GOROOT="/usr/lib/go" GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build528676691=/tmp/go-build -gno-record-gcc-switches" CXX="g++" CGO_ENABLED="1" PKG_CONFIG="pkg-config" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2"

What did you do?

What did you expect to see?

An error because json is not valid.

What did you see instead?

No errors.

Copy link

IMO this is working as intended. Your example contains two fragments of json {} which is valid, and } which is not. The json package correctly detects the malformed second json fragment.

Copy link

What @dcheney-atlassian said. The docs do say:

A Decoder reads and decodes JSON values from an input stream.
Decode reads the next JSON-encoded value from its input and stores it in the value pointed to by v.

If you only want to read one element, use Unmarshal or use to see if EOF is next.

@mikioh mikioh changed the title Invalid json is parsed ok encoding/json: Invalid json is parsed ok Aug 2, 2017
@golang golang locked and limited conversation to collaborators Aug 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

4 participants