- 
                Notifications
    You must be signed in to change notification settings 
- Fork 890
Open
Description
code
package main
import (
	"fmt"
	"github.com/tidwall/gjson"
)
func main() {
	ret := []byte(`{
		"result": {
			"data": [
				{"data": [{"type": "quan", "value": 1}, {"type": "quan", "value": 2}, {"type": "quan", "value": 3},  {"type": "other", "value": 4}]},
				{"data": [{"type": "quan", "value": 3}]}
			]
		}
	}`)
	path := "result.data.#.data.#(type==\"quan\")"
	result := gjson.GetBytes(ret, path)
	fmt.Println(result, result.Paths(string(ret)))
	path = "result.data.#.data.#(type==\"quan\")#"
	result = gjson.GetBytes(ret, path)
	fmt.Println(result, result.Paths(string(ret)))
}
output
[{"type": "quan", "value": 1},{"type": "quan", "value": 3}] [result.data.0.data.0 result.data.1.data.0]
[[{"type": "quan", "value": 1},{"type": "quan", "value": 2},{"type": "quan", "value": 3}],[{"type": "quan", "value": 3}]] [ ]
Metadata
Metadata
Assignees
Labels
No labels