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

No error reported for invalid raw json with ValidateJsonRawMessage = true #558

Open
rocurley opened this issue Jun 23, 2021 · 1 comment · May be fixed by #584
Open

No error reported for invalid raw json with ValidateJsonRawMessage = true #558

rocurley opened this issue Jun 23, 2021 · 1 comment · May be fixed by #584

Comments

@rocurley
Copy link

Expected result: when attempting to serialize invalid raw json, when ValidateJsonRawMessage = true, an error should be returned.
Actual result: no error is returned. Instead, the invalid raw json is serialized as null.

package main

import (
	"encoding/json"
	"fmt"

	jsoniter "github.com/json-iterator/go"
)

func main() {
	invalidMessage := json.RawMessage("unescaped string")
	encResult, encErr := json.Marshal(invalidMessage)
	fmt.Println("Standard lib:")
	fmt.Println(string(encResult))
	fmt.Println(encErr)
	iterResult, iterErr := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(invalidMessage)
	fmt.Println("jsoniter:")
	fmt.Println(string(iterResult))
	fmt.Println(iterErr)
}

Result:

Standard lib:

json: error calling MarshalJSON for type json.RawMessage: invalid character 'u' looking for beginning of value
jsoniter:
null
<nil>
@kucharskilukasz
Copy link

Is there a plan to merge it with the master branch and close that issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants