Skip to content
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

Result Array() function misleading comments #240

Closed
hyde-zhang opened this issue Oct 12, 2021 · 1 comment
Closed

Result Array() function misleading comments #240

hyde-zhang opened this issue Oct 12, 2021 · 1 comment

Comments

@hyde-zhang
Copy link

The Result Array() function doesn't do what the comments says.

nonArrayData := "{\"jsonrpc\":\"2.0\",\"method\":\"subscription\",\"params\":{\"channel\":\"funny_channel\",\"data\":{\"name\":\"Jason\",\"company\":\"good_company\",\"number\":12345}}}"
parsed := gjson.Parse(nonArrayData)

for _, doc := range parsed.Get("params.data").Array() {
    log.Println(doc.Raw) // not called
}

arrayData := "{\"jsonrpc\":\"2.0\",\"method\":\"subscription\",\"params\":{\"channel\":\"funny_channel\",\"data\":[{\"name\":\"Jason\",\"company\":\"good_company\",\"number\":12345}]}}"
parsed = gjson.Parse(arrayData)

for _, doc := range parsed.Get("params.data").Array() {
    log.Println(doc.Raw)
}

Think the issue is this i.e. it skips too much. Either update the function commends or please don't skip '{'

@tidwall
Copy link
Owner

tidwall commented Oct 12, 2021

Thanks for reporting! I found the issue and fixed it in v1.9.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants