From 3a977634ebda612fd9c03f996da37a51ec504b14 Mon Sep 17 00:00:00 2001 From: speier Date: Fri, 27 Apr 2018 15:54:16 +0200 Subject: [PATCH] valid bytes method --- gjson.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gjson.go b/gjson.go index 241bd6d..813c71e 100644 --- a/gjson.go +++ b/gjson.go @@ -2058,6 +2058,20 @@ func Valid(json string) bool { return ok } +// ValidBytes returns true if the input is valid json. +// +// if !gjson.Valid(json) { +// return errors.New("invalid json") +// } +// value := gjson.Get(json, "name.last") +// +// If working with bytes, this method preferred over Valid(string(data)) +// +func ValidBytes(json []byte) bool { + _, ok := validpayload(json, 0) + return ok +} + func parseUint(s string) (n uint64, ok bool) { var i int if i == len(s) {