Ok, so I looked at the https://github.com/tidwall/gjson/blob/master/gjson.go code, and see that the jsonvals slice is a slice of:
type Result struct { // Type is the json type Type Type // Raw is the raw json Raw string // Str is the json string Str string // Num is the json number Num float64 // Index of raw value in original json, zero means index unknown Index int } So you will need to locate the index of the "ID" field in the slice and presumably access the Num field. something like: fmt.Printf("\n%+v\n", jsonvals[2].Num) Good Luck, - Jake On Monday, March 12, 2018 at 12:32:34 PM UTC-4, Jake Montgomery wrote: > > I have not run this. But based on your comments, jsonvals is a slice. So > you would presumably need to check the length then access a specific item > in the slice like this: fmt.Printf("\n%+v\n", jsonvals[0].ID) > > Hope that helps. > > > > On Monday, March 12, 2018 at 12:01:33 PM UTC-4, asyncp...@gmail.com wrote: >> >> Go Noob here, confused about struct. My result is type []gjson.Result but >> I can't extract a named value from this struct. Help greatly appreciated, I >> have tried several articles. >> >> package main >> >> import ( >> "fmt" >> "github.com/tidwall/gjson" >> "reflect" >> ) >> >> >> func main() { >> // JSON package gjson >> const json = `{"pass":true,"balance":180,"who":"f","ID":4231}]` >> >> jsonvals := gjson.GetMany(string(json), "pass", "balance", "ID") >> fmt.Printf("%+v\n", jsonvals) // result: [true 180 4231] >> fmt.Println(reflect.TypeOf(jsonvals)) // result: []gjson.Result >> fmt.Printf("\n%+v\n", jsonvals.ID) // fails here, why? it is a struct, >> right??? >> >> } >> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.