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

duck-type values responding to #to_hash or #to_ary #139

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

notEthan
Copy link
Contributor

@notEthan notEthan commented Jan 4, 2022

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.

@notEthan
Copy link
Contributor Author

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 (jmespath/jmespath.rb#51). I'd like to have both flavors of json querying available as options that are compatible with my library.

@joshbuddy
Copy link
Owner

Sorry about the delay.

This change makes total sense to me. Looking forward to the PR and thanks!

@blambeau
Copy link
Contributor

blambeau commented Jul 2, 2022

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).

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

Successfully merging this pull request may close these issues.

3 participants