In Go, what's the best way of loading the value of a single entry of a json object that doesn't involve writing your own json parser?
So far, the best way I've found involvs reflect
: you build a struct with a single field tagged with the entry you're looking for. Needs 1.7+. If you can't use that (and that's a shame as it's the only one that isn't O(N) memory), stepping through the tokens seems to be the next best bet.
$ /snap/bin/go test . -bench=. -benchmem -v
goos: linux
goarch: amd64
Benchmark______0_Full-8 300000 4078 ns/op 21.09 MB/s 1408 B/op 40 allocs/op
Benchmark_____10_Full-8 50000 40087 ns/op 22.90 MB/s 9989 B/op 371 allocs/op