mdaverde / jsonpath

jsonpath golang library to help with getting and setting values on paths (even nonexistent paths)
https://pkg.go.dev/github.com/mdaverde/jsonpath
MIT License
22 stars 5 forks source link

Does this support slice? #1

Closed coopci closed 2 years ago

coopci commented 6 years ago

slice like [,], I tried this:

func must(err error) { return } func main() { sample := { "owner": { "name": "john doe", "contact": { "phone": "555-555-5555" }, "arr1": ["ele1", "ele2", "ele3"] } }

var payload interface{}

err := json.Unmarshal([]byte(sample), &payload)
must(err)

ele1, err := jsonpath.Get(payload, "owner.arr1[0,1]")
must(err)
fmt.Printf("ele1: %s \n", ele1)

}

And it prints ele1: %!s(). And I found jasonpath.go line54 calls strconv.Atoi(token) to parse token.

mdaverde commented 2 years ago

This does not support slice currently. Work needs to be done to add more of the JSONPath spec