fastjson
fastjson copied to clipboard
Can I use one `Parser` repeatedly?
I want to define a Parser only one time, and use it to parse different string several times. But it seems that the variables only are assigned with the latest parsing result, even I use different variable. My demo code as follows:
package main
import "fmt"
import "github.com/valyala/fastjson"
func main() {
var p fastjson.Parser
s0 := `{"hello": "world"}`
s1 := `{"hello": "dlrow"}`
v, _ := p.Parse(s0)
v1, _ := p.Parse(s1)
fmt.Printf("%v\n", v.Get("hello"))
fmt.Printf("%v\n", v1.Get("hello"))
}
Parser can be used repeatedly. Moreover - this is the most optimal usage for Parser. But all the objects returned from the Parse call become invalid after the next Parse call.
Any methods to keep it valid?
ParserPool may be used for pooling Parsers for similarly typed JSONs.
https://godoc.org/github.com/valyala/fastjson#ParserPool
What are the disadvantages of reusing a parser pool for infinitely dissimilar json?
Boundless memory consumption?