gjson 是一个 Go 开发包,提供了非常快速和简单的方式来获得一个 JSON 文档的值。此文库的存在是为 BuntDB 项目提供高效的 JSON 索引。
开始使用 GJSON,安装 Go ,并运行go get:
$ go get -u github.com/tidwall/gjson
此操作可恢复文库。
与 encoding/json, ffjson, EasyJSON, 和 jsonparser 并列的 GJSON 基准点。
BenchmarkGJSONGet-8 15000000 333 ns/op 0 B/op 0 allocs/op BenchmarkGJSONUnmarshalMap-8 900000 4188 ns/op 1920 B/op 26 allocs/op BenchmarkJSONUnmarshalMap-8 600000 8908 ns/op 3048 B/op 69 allocs/op BenchmarkJSONUnmarshalStruct-8 600000 9026 ns/op 1832 B/op 69 allocs/op BenchmarkJSONDecoder-8 300000 14339 ns/op 4224 B/op 184 allocs/op BenchmarkFFJSONLexer-8 1500000 3156 ns/op 896 B/op 8 allocs/op BenchmarkEasyJSONLexer-8 3000000 938 ns/op 613 B/op 6 allocs/op BenchmarkJSONParserGet-8 3000000 442 ns/op 21 B/op 0 allocs/op
JSON 文档使用:
{ "widget": { "debug": "on", "window": { "title": "Sample Konfabulator Widget", "name": "main_window", "width": 500, "height": 500 }, "image": { "src": "Images/Sun.png", "hOffset": 250, "vOffset": 250, "alignment": "center" }, "text": { "data": "Click Here", "size": 36, "": "bold", "vOffset": 100, "alignment": "center", "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" } } }
每个操作都是通过下面的搜索路径之一回转:
widget.window.name widget.image.hOffset widget.text.onMouseU