Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/jsonpath/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def each(context = @object, key = nil, pos = 0, &blk)
case node
when Hash, Array
(node.is_a?(Hash) ? node.keys : (0..node.size)).each do |e|
each(node, e, pos + 1) { |n|
@_current_node = n
yield n if process_function_or_literal(sub_path[1, sub_path.size - 1])
}
@_current_node = node[e]
if process_function_or_literal(sub_path[1, sub_path.size - 1])
each(@_current_node, nil, pos + 1, &blk)
end
end
else
yield node if process_function_or_literal(sub_path[1, sub_path.size - 1])
Expand Down
4 changes: 4 additions & 0 deletions test/test_jsonpath.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def test_support_filter_by_childnode_value_with_inconsistent_children
assert_equal [@object['store']['book'][3]], JsonPath.new("$..book[?(@.price > 20)]").on(@object)
end

def test_support_filter_by_childnode_value_and_select_child_key
assert_equal [23], JsonPath.new("$..book[?(@.price > 20)].price").on(@object)
end

def example_object
{ "store"=> {
"book" => [
Expand Down