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: export func Valid([]byte) bool #18086

Closed
sj26 opened this issue Nov 28, 2016 · 4 comments
Closed

encoding/json: export func Valid([]byte) bool #18086

sj26 opened this issue Nov 28, 2016 · 4 comments
Labels
FrozenDueToAge help wanted Proposal-Accepted Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@sj26
Copy link

sj26 commented Nov 28, 2016

I'm running go version go1.7.1 darwin/amd64 on macOS 10.12.1.

I'm trying to validate some a byte array is valid JSON so it can be marshalled literally like RawMessage. The only way to do this at the moment is to create a Decoder and fully decode the bytes causing many useless allocations, or write a custom scanner.

But there's a lovely, allocation-free function for scanning a byte array to see if it's valid JSON tucked away inside the encoding/json package (checkValid), and used in several places within the package. It'd be great to expose this for general use as something like IsValid(data []byte) bool.

I proposed this change a while back but I didn't understand the contribution process sorry! Is this the right place to file the issue @bradfitz?

@bradfitz bradfitz changed the title encoding/json: Expose efficient validation proposal: encoding/json: expose efficient validation Nov 28, 2016
@bradfitz bradfitz added this to the Proposal milestone Nov 28, 2016
@bradfitz
Copy link
Contributor

@sj26, we just had a proposal review meeting today, so this'll be discussed at the next one, usually weekly.

I'll let others chime in here in the meantime.

@rsc
Copy link
Contributor

rsc commented Dec 12, 2016

By analogy with unicode/utf8's func Valid, it seems like this should be encoding/json's func Valid.

@rsc
Copy link
Contributor

rsc commented Dec 12, 2016

If you (or anyone else) would like to send a CL, please do, for Go 1.9.

@rsc rsc changed the title proposal: encoding/json: expose efficient validation encoding/json: export func Valid([]byte) bool Dec 12, 2016
@rsc rsc modified the milestones: Go1.9, Proposal Dec 12, 2016
@bradfitz bradfitz added help wanted Suggested Issues that may be good for new contributors looking for work to do. labels Dec 12, 2016
@gopherbot
Copy link

CL https://golang.org/cl/34202 mentions this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted Proposal-Accepted Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

4 participants