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

Multiple calls to Find returns nil #59

Open
tomelm opened this issue Aug 30, 2019 · 4 comments
Open

Multiple calls to Find returns nil #59

tomelm opened this issue Aug 30, 2019 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@tomelm
Copy link

tomelm commented Aug 30, 2019

I'm trying to use gojsonq to make some queries to JSON data. I was setting up some tests that were returning nil when I tried to validate the data inside of the JSON object. Eventually, I noticed if I do multiple Finds, it starts returning nil.

Here's an example of the behavior: https://play.golang.org/p/qxiooDmflIe

Is this expected? I couldn't find a way in the documentation to run the same query multiple times and get the same data back.

@Kvaz1r
Copy link
Contributor

Kvaz1r commented Aug 31, 2019

Yes, it's expected. Query it's like a chain if you move forward you can't automatically return back to previous state.
There is Reset/0 method.
Although it would be great to have opportunity save current state and return not only to start point.

@thedevsaddam
Copy link
Owner

I appreciate the thought, it would be great if the reset calls invoke automatically. This can be an improvement.

@thedevsaddam thedevsaddam self-assigned this Aug 31, 2019
@thedevsaddam thedevsaddam added the enhancement New feature or request label Aug 31, 2019
@tomelm
Copy link
Author

tomelm commented Sep 3, 2019

Thanks @Kvaz1r, that's what I was looking for! Maybe for Find it automatically resets since it seems like users won't really be building queries with that?

@joe94
Copy link

joe94 commented Jun 11, 2020

Yeah, an efficient reset would be nice here for uses cases where we want to initialize the query object given a map and then just query for specific values given their paths many times.

Also https://github.com/thedevsaddam/gojsonq/wiki/Queries#findpath mentions that

Caveat: You can't chain further query methods after it. If you need that, you should use From() method

so it's be compatible with the design.

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

No branches or pull requests

4 participants