-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] examples of usage? #22
Comments
Sorry for the delay here. The type of data it expects is as you've mentioned: the output of The return value right now will depend on the what the expression is, so for example, your expression above of I'm certainly open to suggestions to improve this. Would you want something like |
The following works for me: package main
import (
"encoding/json"
"log"
"github.com/jmespath/go-jmespath"
)
func main() {
var jsonBlob = []byte(`{"name":"ben", "items": [{"age":38}]}`)
var d interface{}
err := json.Unmarshal(jsonBlob, &d)
if err != nil {
log.Fatal(err)
}
v, err := jmespath.Search("items[0].age", d)
if err != nil {
log.Fatal(err)
}
log.Println(v)
} |
@jamesls Hard to tell to be honest... after a year I totally don't remember what I needed it for :) @JalfResi thanks for the example! |
I agree that this can be closed now, with @JalfResi posted example. |
Hi, I mostly wonder what kind of data jmespath.Search() expects?
Param data says
interface{}
so it's not really helpful... can I use string{}
or[]byte("{}")
or what it should be?From testcases I see that
map[string]interface{}
is used so it looks like output of json.Unmarshal... but is this the only data type that can be passed? Or maybe json string is allowed too?Same questions apply to return value... what kind of data types I can expect?
interface{}
type suggest I can expect various data types, or maybe even self defined ones... but there is no info about it... so no idea what should I try to assert.I was trying to do something simple like:
but this doesn't seem to work
Also, considering jmespath.Search() returns
interface{}
then beside type assertion is there any nicer way to convert this some usable data type? Likestring
or[]byte
or self definedstruct
(e.g. like with json.Unmarshal)?The text was updated successfully, but these errors were encountered: