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

Feature request: Querying Path #8

Closed
omani opened this issue Aug 31, 2017 · 8 comments
Closed

Feature request: Querying Path #8

omani opened this issue Aug 31, 2017 · 8 comments

Comments

@omani
Copy link

omani commented Aug 31, 2017

Hi,

like in gjson:

name := gjson.Get(json, `programmers.#[lastName="Hunter"].firstName`)
println(name.String())  // prints "Elliotte"

It would be nice if one could set a field by querying for it. because right now I would like to update an object within an array. and I don't know the index beforehand.

any plans to implement this?

@omani
Copy link
Author

omani commented Aug 31, 2017

another approach would be to have a method on gjson to get the index of the found element (from above name's methods). then I could easily update via sjson by giving an index integer/string.

@omani
Copy link
Author

omani commented Aug 31, 2017

just found out that there is a method for getting the index position. seems to be name.Int().

you can consider this issue as closed. but querying a path would be nice nevertheless.

@tidwall
Copy link
Owner

tidwall commented Aug 31, 2017

Hi @omani,

I wrote the https://github.com/tidwall/sjson library that can be used for updating values. Though some paths, such as ones that have '#' character may not be updatable.

@tidwall
Copy link
Owner

tidwall commented Aug 31, 2017

Sorry about the weird response. I thought this issue was filed on the gjson project.

@tidwall
Copy link
Owner

tidwall commented Aug 31, 2017

This would be a pretty nice feature and something I'll keep in mind for a future release.

@omani
Copy link
Author

omani commented Aug 31, 2017

thanks for the quick response. yeah hope to see it sometime. the Int() method did the job for me for now.

thanks.

@omani omani closed this as completed Aug 31, 2017
@tidwall
Copy link
Owner

tidwall commented Aug 31, 2017

Glad to hear 👍

@omani
Copy link
Author

omani commented Sep 3, 2017

I realized method Int() is not the way to go here. new issue is tidwall/gjson#41.

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