Created
October 18, 2016 22:46
-
-
Save nst/bef1b7ebf36bd1fa2733e81e5350fde5 to your computer and use it in GitHub Desktop.
A quick assessment of Go JSON parser conformance to RFC 7159
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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