I ran the parsing test cases from https://github.com/nst/JSONTestSuite against both json.Valid() and jsoniter.Valid(). There are several cases where they give differing results.
This workaround adapted from what @JeckieLI provided in #519 addresses a lot of the issues:
func validWorkaround(data []byte) bool {
data = append(data, '\n')
iter := jsoniter.ConfigCompatibleWithStandardLibrary.BorrowIterator(data)
defer jsoniter.ConfigCompatibleWithStandardLibrary.ReturnIterator(iter)
iter.Skip()
if iter.Error != nil {
return false
}
iter.WhatIsNext()
return iter.Error == io.EOF
}
The table below shows the cases with differing results. I bolded the rows where the workaround doesn't address the problem. The test cases are named such that the ones starting with "y" are valid json, the ones starting with "n" are invalid json and the ones starting with "i" are ambiguous according the the relevant RFCs.
I ran the parsing test cases from https://github.com/nst/JSONTestSuite against both
json.Valid()
andjsoniter.Valid()
. There are several cases where they give differing results.This workaround adapted from what @JeckieLI provided in #519 addresses a lot of the issues:
The table below shows the cases with differing results. I bolded the rows where the workaround doesn't address the problem. The test cases are named such that the ones starting with "y" are valid json, the ones starting with "n" are invalid json and the ones starting with "i" are ambiguous according the the relevant RFCs.
json.Valid()
json.Valid
validWorkaround