thedevsaddam / gojsonq

A simple Go package for querying over JSON, YAML, XML, and CSV data.
https://github.com/thedevsaddam/gojsonq/wiki
MIT License
2.19k stars 140 forks source link

call Find() twice with the same path but got nil for the second time #103

Open Boyy-Next-Door opened 1 year ago

Boyy-Next-Door commented 1 year ago
        jq := gojsonq.New().FromString(string(data))
    path1 := fmt.Sprintf("data.dynamicConfig.%s.feConfig.areaLevel", req["corpId"].(string))
    areaLevel := jq.Find(path1)     // got correct value    interface{} | float64 => 3
    areaLevel2 := jq.Find(path1)   // got interface{}  => nil

Is there anything wrong in this use case ? 😭

Boyy-Next-Door commented 1 year ago

oh! I realized that I need to call Reset() before Find() again!

    areaLevel := jq.Find(fmt.Sprintf("data.dynamicConfig.%s.feConfig.areaLevel", req["corpId"].(string)))
    areaRange := jq.Reset().Find(fmt.Sprintf("data.dynamicConfig.%s.feConfig.areaRange", req["corpId"].(string)))
kshji commented 1 year ago

I done also lot of ... before found this info. And saw Reset() wiki. I hope you add to the basic examples: a) make more than one query to the source - after readed json file b) how to use query after query without reset