diff --git a/CHANGELOG.md b/CHANGELOG.md index 81cb93e..9c4e2c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # vNext +# v1.3.2 + +- (feature) Add validate mehtod to custom json un/marshall functions + # v1.3.1 - (feature) Add custom json un-/marshall functions diff --git a/json/valid.go b/json/valid.go new file mode 100644 index 0000000..7ac6f0e --- /dev/null +++ b/json/valid.go @@ -0,0 +1,22 @@ +package json + +import ( + stdjson "encoding/json" + "runtime" + + "github.com/Becklyn/go-wire-core/env" + "github.com/bytedance/sonic" + "github.com/goccy/go-json" +) + +func Valid(data []byte) bool { + if env.StringWithDefault("JSON_ENCODER", "std") == "std" { + return stdjson.Valid(data) + } + + if runtime.GOARCH == "amd64" { + return sonic.Valid(data) + } + + return json.Valid(data) +}