Skip to content

Instantly share code, notes, and snippets.

@nst
Created October 18, 2016 22:46
Show Gist options
  • Save nst/bef1b7ebf36bd1fa2733e81e5350fde5 to your computer and use it in GitHub Desktop.
Save nst/bef1b7ebf36bd1fa2733e81e5350fde5 to your computer and use it in GitHub Desktop.
A quick assessment of Go JSON parser conformance to RFC 7159
// go build test_json.go
// echo -n "[1e1000]" > n.json
// ./test_json n.json
// echo $? # 0 - failed to parse valid JSON
// echo -en '["\xFF"]' > s.json
// ./test_json s.json
// echo $? # 1 - parsed invalid JSON
package main
import "encoding/json"
import "io/ioutil"
import "os"
func main() {
b, file_err := ioutil.ReadFile(os.Args[1])
if file_err != nil {
os.Exit(-1)
}
var f interface{}
err := json.Unmarshal(b, &f)
if err != nil {
os.Exit(1)
}
os.Exit(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment