valyala / fastjson

Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provide a GetString to get string type instead of byte slice

goodspark opened this issue · comments

Could we get a function to just return the string type instead of a byte slice?

I often just need the string and noticed GetStringByte is actually converting the underlying string to a byte.

func (v *Value) GetString(keys ...string) string {
  v = v.Get(keys...)
  if v == nil || v.Type() != TypeString {
    return ""
  }
  return v.s
}

This won't work, since v.s is backed by byte slice, which changes on the next Parser.Parse call. This means that the returned string contents will become garbage on the next Parser.Parse call.