tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
14.1k stars 846 forks source link

Can Array.Foreach key=array.index? #248

Closed itmaple closed 2 years ago

itmaple commented 2 years ago
array.ForEach(func(key, value gjson.Result) bool {
    // key -> 0 or 1 or 2 ...
}
tidwall commented 2 years ago

Yes. I think that this can be made so. While an array does not really have a key like an object, we can easily produce one behind the scenes.

I think for now we should only fill the key.Num and key.Type fields. We'll leave the key.Raw and others empty.

This'll allow for key.String() and key.Int() to return the string and integer representation of the array index.

tidwall commented 2 years ago

I just added this feature. Thanks for the suggestion.

itmaple commented 2 years ago

Yep!Thanks.