针对json的查询--alibaba的开源项目jsonq
项目地址:
https://github.com/alibaba/jsonq
示例json
{ "foo": 1, "bar": 2, "test": "Hello, world!", "baz": 123.1, "array": [ {"foo": 1}, {"bar": 2}, {"baz": 3} ], "subobj": { "foo": 1, "subarray": [1,2,3], "subsubobj": { "bar": 2, "baz": 3, "array": ["hello", "world"] } }, "bool": true }
调用
import ( "strings" "encoding/json" "github.com/jmoiron/jsonq" ) data := map[string]interface{}{} dec := json.NewDecoder(strings.NewReader(jsonstring)) dec.Decode(&data) jq := jsonq.NewQuery(data)