jsonpath
jsonpath copied to clipboard
duck-type values responding to #to_hash or #to_ary
I work with JSON data wrapped in classes which behave like Hash and Array, which respond to #to_hash / #to_ary to support implicit conversion (as described in https://docs.ruby-lang.org/en/master/doc/implicit_conversion_rdoc.html )
this PR lets jsonpath be used with these implicitly convertible objects. my goal is to search the wrapped document and get wrapped children out as the result(s).
it is in draft because I have updated no tests, and may be incomplete in other ways. if an active maintainer thinks it is a good idea to merge, I will bring it to completion.
I hope any maintainers will consider this. that is, a thumbs up that it could be merged/released if I put the rest of the work in to get this PR complete.
I've implemented the same changes on jmespath for ruby (https://github.com/jmespath/jmespath.rb/pull/51). I'd like to have both flavors of json querying available as options that are compatible with my library.
Sorry about the delay.
This change makes total sense to me. Looking forward to the PR and thanks!
Just a comment on the PR.
I think to_h should be supported instead (or in addition to) to_hash. The former is standard IMO, the latter is not (but widely used).