jsonpath 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/jsonpath/enumerable.rb +9 -3
- data/lib/jsonpath/version.rb +1 -1
- data/lib/jsonpath.rb +3 -5
- data/test/test_jsonpath.rb +11 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89da09f37794d1cf177f887ea0a6c7d0da21d7106f8fd92d74d0615148feca02
|
4
|
+
data.tar.gz: 116f72d5493e540e5fde487dac9e57c3ff7f4c5122b66997a09eea899cda59a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25d571cacbb85435c838c25b5d3c9cd8d6d1c11b743927531af80cdfe45d4670e6e37b21030608cf2b2ff4c04c78033caeb492ceb76db24e5b35d9a514b9e669
|
7
|
+
data.tar.gz: 1b0fa8cdc648f6d889f00cd751e3e03e7f32693a5897238584d0ee67e3e3542117901755393bb36e513be6addc2fd4ab3223782df005f20024763cc14e0fc350
|
data/README.md
CHANGED
data/lib/jsonpath/enumerable.rb
CHANGED
@@ -21,9 +21,13 @@ class JsonPath
|
|
21
21
|
when '*', '..', '@'
|
22
22
|
each(context, key, pos + 1, &blk)
|
23
23
|
when '$'
|
24
|
-
|
24
|
+
if node == @object
|
25
|
+
each(context, key, pos + 1, &blk)
|
26
|
+
else
|
27
|
+
handle_wildcard(node, "['#{expr}']", context, key, pos, &blk)
|
28
|
+
end
|
25
29
|
when /^\[(.*)\]$/
|
26
|
-
|
30
|
+
handle_wildcard(node, expr, context, key, pos, &blk)
|
27
31
|
when /\(.*\)/
|
28
32
|
keys = expr.gsub(/[()]/, '').split(',').map(&:strip)
|
29
33
|
new_context = filter_context(context, keys)
|
@@ -51,7 +55,7 @@ class JsonPath
|
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
54
|
-
def
|
58
|
+
def handle_wildcard(node, expr, _context, _key, pos, &blk)
|
55
59
|
expr[1, expr.size - 2].split(',').each do |sub_path|
|
56
60
|
case sub_path[0]
|
57
61
|
when '\'', '"'
|
@@ -64,6 +68,7 @@ class JsonPath
|
|
64
68
|
else
|
65
69
|
next if node.is_a?(Array) && node.empty?
|
66
70
|
next if node.nil? # when default_path_leaf_to_null is true
|
71
|
+
next if node.size.zero?
|
67
72
|
|
68
73
|
array_args = sub_path.split(':')
|
69
74
|
if array_args[0] == '*'
|
@@ -81,6 +86,7 @@ class JsonPath
|
|
81
86
|
next unless end_idx
|
82
87
|
next if start_idx == end_idx && start_idx >= node.size
|
83
88
|
end
|
89
|
+
|
84
90
|
start_idx %= node.size
|
85
91
|
end_idx %= node.size
|
86
92
|
step = process_function_or_literal(array_args[2], 1)
|
data/lib/jsonpath/version.rb
CHANGED
data/lib/jsonpath.rb
CHANGED
@@ -45,11 +45,9 @@ class JsonPath
|
|
45
45
|
elsif (token = scanner.scan(/[><=] \d+/))
|
46
46
|
@path.last << token
|
47
47
|
elsif (token = scanner.scan(/./))
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
raise ArgumentError, "character '#{token}' not supported in query"
|
52
|
-
end
|
48
|
+
@path.last << token
|
49
|
+
else
|
50
|
+
raise ArgumentError, "character '#{scanner.peek(1)}' not supported in query"
|
53
51
|
end
|
54
52
|
end
|
55
53
|
end
|
data/test/test_jsonpath.rb
CHANGED
@@ -1178,6 +1178,10 @@ class TestJsonpath < MiniTest::Unit::TestCase
|
|
1178
1178
|
assert_raises(MultiJson::ParseError) { JsonPath.new('$.a', max_nesting: 1).on(json) }
|
1179
1179
|
end
|
1180
1180
|
|
1181
|
+
def test_linefeed_in_path_error
|
1182
|
+
assert_raises(ArgumentError) { JsonPath.new("$.store\n.book") }
|
1183
|
+
end
|
1184
|
+
|
1181
1185
|
def test_with_max_nesting_false
|
1182
1186
|
json = {
|
1183
1187
|
a: {
|
@@ -1260,4 +1264,11 @@ class TestJsonpath < MiniTest::Unit::TestCase
|
|
1260
1264
|
}
|
1261
1265
|
assert_equal ["$", "$.foo", "$.bar", "$.bar.baz", "$.bars", "$.bars[0].foo", "$.bars[0]", "$.bars[1].foo", "$.bars[1]", "$.bars[2]"], JsonPath.fetch_all_path(data)
|
1262
1266
|
end
|
1267
|
+
|
1268
|
+
|
1269
|
+
def test_extractore_with_dollar_key
|
1270
|
+
json = {"test" => {"$" =>"success", "a" => "123"}}
|
1271
|
+
assert_equal ["success"], JsonPath.on(json, "$.test.$")
|
1272
|
+
assert_equal ["123"], JsonPath.on(json, "$.test.a")
|
1273
|
+
end
|
1263
1274
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonpath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hull
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-05-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
|
-
rubygems_version: 3.
|
162
|
+
rubygems_version: 3.4.1
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: Ruby implementation of http://goessner.net/articles/JsonPath/
|