This is a wishlist of how I want the query language to look.
The only things on here that work right now are get s and get ns.
I haven't yet decided if I actually want to support sets due to how the indexing works through a hash. It would be cumbersome to try and pass a big value into dictdots in the query string.
Get returns a specific object matching an exact query.
smatch a specific key, e.g.hello.goodbyewould get"world"from:{ "hello": { "goodbye": "world" }, }nmatch specific index in a list. e.g.0.hellowould get"world"from:[ {"hello": "world"}, ]nmatch an integer key. e.g.1.2would get"why are you using int keys?"from:{ 1: { 2: "why are you using int keys?", }, }nfnmatch a float keyn.n, e.g.100f04gets"e"from{100.04: "e"}.nsmatch a numeric stringn, e.g.100swould get"e"from{"100": "e"}.{s}match a specific index in a set. e.g.{hello}would get "hello" from{"hello", "world"}. This seems somewhat useless.
Filter returns a list of objects that matched the query and an empty list if there were no matches.
Supports all get query args.
[]means match any index in a list. Return any objects in list that match the query after the[]. e.g.[].foowould get["t", "bar"]from:[ {"foo": "t"}, {"foo": "bar"}, {"no": "match"}, ]{}match any key in a dictionary. Return any values that match the query after the{{}}. e.g.{}.sierrawould get["117", "034"]from:{ "hello": {"sierra": "117"}, "goodbye": {"sierra": "034"}, "morning": {"no": "match"}, }{,}match any index in a set. Return a set of values that match the query after the{{s}}. e.g.{,}.sierrawould get[117, ]from:{ {"sierra": 117}, {"the fall of": "reach"}, }
Uses the same logic as get, but returns a boolean instead of the value.
Checks if the key exists rather than grabbing the value.
Must still return True even if the value is falsey.
e.g.
bob = {
"sierra_117": False,
"sandtrap": "",
"endless": None,
}
assert DictDots.exists(bob, "sierra_117")
assert DictDots.exists(bob, "sandtrap")
assert DictDots.exists(bob, "endless")should all pass.