Skip to content

Commit 9eb3d04

Browse files
authored
Merge pull request #157 from anuravi98/master
Jsonpath with keyname $ not working
2 parents 26f6570 + 268c672 commit 9eb3d04

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ o = JsonPath.for(json).
255255

256256
### Fetch all paths
257257

258-
To fetch all possible paths in given json, you can use `fetch_all_paths` method.
258+
To fetch all possible paths in given json, you can use `fetch_all_path`` method.
259259
260260
data:
261261

lib/jsonpath/enumerable.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ def each(context = @object, key = nil, pos = 0, &blk)
2121
when '*', '..', '@'
2222
each(context, key, pos + 1, &blk)
2323
when '$'
24-
each(context, key, pos + 1, &blk) if node == @object
24+
if node == @object
25+
each(context, key, pos + 1, &blk)
26+
else
27+
handle_wildecard(node, "['#{expr}']", context, key, pos, &blk)
28+
end
2529
when /^\[(.*)\]$/
2630
handle_wildecard(node, expr, context, key, pos, &blk)
2731
when /\(.*\)/

test/test_jsonpath.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,4 +1260,11 @@ def test_fetch_all_path
12601260
}
12611261
assert_equal ["$", "$.foo", "$.bar", "$.bar.baz", "$.bars", "$.bars[0].foo", "$.bars[0]", "$.bars[1].foo", "$.bars[1]", "$.bars[2]"], JsonPath.fetch_all_path(data)
12621262
end
1263+
1264+
1265+
def test_extractore_with_dollar_key
1266+
json = {"test" => {"$" =>"success", "a" => "123"}}
1267+
assert_equal ["success"], JsonPath.on(json, "$.test.$")
1268+
assert_equal ["123"], JsonPath.on(json, "$.test.a")
1269+
end
12631270
end

0 commit comments

Comments
 (0)