-
Notifications
You must be signed in to change notification settings - Fork 436
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
How to get key by index? #266
Comments
Hi! No, you will have to iterate till needed index, and then return early. But overall performance wise it will be the same. |
How do you return early though? Same for |
I just realized that this works too and solves my problem 👍 var jsonData = []byte(`{
"hello":[{},{}, "{fake-object}" ],
"batch" : [
{
"userId": 123,
"context": {"library":{
"name":"analytics-go",
"version": "1.2.3"
}}
},
{ },
{},
{"inner" : { } }
]
}`)
func TestVersionFromEvent(t *testing.T) {
value, dataType, _, err := jsonparser.Get(jsonData, "batch", "[0]", "context", "library", "version")
require.NoError(t, err)
require.Equal(t, jsonparser.String, dataType)
require.Equal(t, "1.2.3", string(value))
} |
I saw func "eachKey". Do you have func for get key by index?
The text was updated successfully, but these errors were encountered: