added ParseBytes

This commit is contained in:
Josh Baker 2016-12-02 11:59:39 -07:00
parent 1a8de7c426
commit c1e65a498d
1 changed files with 7 additions and 1 deletions

View File

@ -334,7 +334,7 @@ end:
return return
} }
// Parse parses the json and returns a result // Parse parses the json and returns a result.
func Parse(json string) Result { func Parse(json string) Result {
var value Result var value Result
for i := 0; i < len(json); i++ { for i := 0; i < len(json); i++ {
@ -372,6 +372,12 @@ func Parse(json string) Result {
return value return value
} }
// ParseBytes parses the json and returns a result.
// If working with bytes, this method preferred over Parse(string(data))
func ParseBytes(json []byte) Result {
return Parse(string(json))
}
func squash(json string) string { func squash(json string) string {
// expects that the lead character is a '[' or '{' // expects that the lead character is a '[' or '{'
// squash the value, ignoring all nested arrays and objects. // squash the value, ignoring all nested arrays and objects.