jsonpath icon indicating copy to clipboard operation
jsonpath copied to clipboard

duck-type values responding to #to_hash or #to_ary

Open notEthan opened this issue 3 years ago • 3 comments
trafficstars

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 avatar Jan 04 '22 11:01 notEthan

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.

notEthan avatar Jan 19 '22 11:01 notEthan

Sorry about the delay.

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

joshbuddy avatar Jan 19 '22 12:01 joshbuddy

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

blambeau avatar Jul 02 '22 05:07 blambeau