Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go1.7
What operating system and processor architecture are you using (go env)?
linux/amd64 (Arch Linux)
kernel: 4.7.1-1-ARCH
What did you do?
Simply reading a file containing JSON data where in one string a backslash '' is present. At this point it is not meant to escape anything but simply represents malformed JSON. Below an example of what I've done.
For starters I've fixed up a bit of your example to make it a runnable go program but it correctly reports that we have an invalid character 'a' in string
I see in your code
iferr!=nil {
return2
}
Perhaps you aren't catching that status code of 2 in whichever caller is invoking LoadConfig()?
And, yes if it encounters an error it won't set the properties, so please check your errors/status codes.
To test it out without having to make a file; just to make the code sample easily reproducible on the playground at https://play.golang.org/p/W91r6xm-t9 or inlined. As you'll see, we can successfully catch and print the error
I am marking this as not a bug. If you think otherwise, please let me know.
odeke-em
changed the title
unmarshal malformed json doesn't produce an error
encoding/json: unmarshal malformed json doesn't produce an error
Aug 27, 2016
Please answer these questions before submitting your issue. Thanks!
go version
)?go1.7
go env
)?linux/amd64 (Arch Linux)
kernel: 4.7.1-1-ARCH
Simply reading a file containing JSON data where in one string a backslash '' is present. At this point it is not meant to escape anything but simply represents malformed JSON. Below an example of what I've done.
foo.json
{"foo":"b\ar"}
Unmarshal returning a non-nil error describing malformed JSON.
No value of the target struct is set by unmarshal.
From my understanding this should produce an error as not just a single field wasn't read but the whole file.
The text was updated successfully, but these errors were encountered: