-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add API for querying JSON documents #356
Comments
I'm looking for something relatively easy to get started as a contributor so I'd be interested in taking this on. In terms of exact interface, what I had in mind was to define methods to "downcast" a
Then your example would look something like this:
Which isn't quite as elegant as what you described, but seems like a decently intuitive solution, and at least a solid starting point for more discussion. |
@a-lafrance Thanks for looking into this! 😃 I think a first start would be to gather some more information on what other languages do, if anything at all. That should help us get a better understanding of what options we might want to consider. In theory we could have query methods returning types like
The downside is that each query would have to allocate a new value, which I'd like to avoid if at all possible. |
I just looked at how The gist is that their JSON type has a So the example here would become Edit: I should probably also note that |
@a-lafrance I like the Serde approach 😃, though we'd have to use separate methods as we don't support argument overloading. So I think we'd end up with This means that for something like this: {
"name": "Alice",
"houses": [
{
"street": "Foo street",
"number": 42,
}
]
} You'd write the query like so:
|
So serde actually has just one indexing method that works for both objects and arrays because it's generic over some special Anyway, not sure if you're interested into looking into that traits/generics approach or if proceeding with the |
@a-lafrance Separate methods would be better. If we use a single method with some sort of |
Gotcha, makes sense. If we’re happy enough with the current interface we’ve outlined I can move forward with implementation. |
@a-lafrance That sounds like a good idea, so feel free to start on the changes 😃 |
@a-lafrance Are you still looking into this, or is it OK for somebody else to pick this up if they want to? |
Hey, sorry for the inactivity — I’ve been on a variety of out of town errands/vacations since our initial discussion so I haven’t been able to implement it myself. I’m planning on working on it when I’m back home in 2 weeks or so, but I don’t want to slow progress just because of my schedule, so if someone else wants to pick it up in the meantime, by all means they’re free to do so :) |
@a-lafrance No problem, and no rush! 😃 |
TODO: write description here. This fixes #356. Changelog: added
TODO: write description here. This fixes #356. Changelog: added
master
introduces thestd::json
module, but querying it is a bit of a pain. For example, given this JSON document:You have to write something like this to extract
42
:Instead it would be nice if one could write something like this instead:
The text was updated successfully, but these errors were encountered: