jmespath 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/jmespath.rb +12 -0
- data/lib/jmespath/caching_parser.rb +1 -2
- data/lib/jmespath/errors.rb +2 -2
- data/lib/jmespath/lexer.rb +19 -22
- data/lib/jmespath/nodes/and.rb +1 -2
- data/lib/jmespath/nodes/comparator.rb +6 -22
- data/lib/jmespath/nodes/condition.rb +3 -2
- data/lib/jmespath/nodes/current.rb +1 -0
- data/lib/jmespath/nodes/expression.rb +2 -2
- data/lib/jmespath/nodes/field.rb +3 -7
- data/lib/jmespath/nodes/flatten.rb +1 -2
- data/lib/jmespath/nodes/function.rb +64 -68
- data/lib/jmespath/nodes/index.rb +1 -0
- data/lib/jmespath/nodes/literal.rb +2 -1
- data/lib/jmespath/nodes/multi_select_hash.rb +1 -0
- data/lib/jmespath/nodes/multi_select_list.rb +1 -0
- data/lib/jmespath/nodes/not.rb +1 -2
- data/lib/jmespath/nodes/or.rb +1 -0
- data/lib/jmespath/nodes/pipe.rb +1 -0
- data/lib/jmespath/nodes/projection.rb +4 -11
- data/lib/jmespath/nodes/slice.rb +13 -18
- data/lib/jmespath/nodes/subexpression.rb +1 -0
- data/lib/jmespath/nodes.rb +3 -4
- data/lib/jmespath/parser.rb +24 -29
- data/lib/jmespath/runtime.rb +1 -2
- data/lib/jmespath/token.rb +3 -4
- data/lib/jmespath/token_stream.rb +4 -5
- data/lib/jmespath/util.rb +5 -5
- data/lib/jmespath/version.rb +1 -0
- data/lib/jmespath.rb +6 -8
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dd359b84687e9959f5ceefc730e01783a02c3c3fd32419112c9cc68bac69fe8
|
4
|
+
data.tar.gz: 19078671387ef295d8d00dfdc6d04758be5d54974b0bf7adfad998af8c0427c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07234d57953b71829d79eeb7862ad7b55b06f96fb6c35ba7b0764ec1339c5b4c6b632b8d3d81ec4a193300e335e371772b54eb91c1092d46eb8ab374afd598b5
|
7
|
+
data.tar.gz: acc8a1daca807053070f8487a76703e45c67da851b3d32753294e67ad67dd7a930ef8f0596ff327c2779aea61b65c2f874ff5bcd4b34df79ba2366d7b6514f43
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.2
|
data/bin/jmespath.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
|
6
|
+
require 'jmespath'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
expression = ARGV[0]
|
10
|
+
json = JSON.parse(STDIN.read)
|
11
|
+
|
12
|
+
$stdout.puts(JSON.dump(JMESPath.search(expression, json)))
|
@@ -1,8 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'thread'
|
2
3
|
|
3
4
|
module JMESPath
|
4
5
|
class CachingParser
|
5
|
-
|
6
6
|
def initialize(options = {})
|
7
7
|
@parser = options[:parser] || Parser.new(options)
|
8
8
|
@mutex = Mutex.new
|
@@ -25,6 +25,5 @@ module JMESPath
|
|
25
25
|
@cache[expression] = @parser.parse(expression)
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
29
28
|
end
|
30
29
|
end
|
data/lib/jmespath/errors.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JMESPath
|
2
4
|
module Errors
|
3
|
-
|
4
5
|
class Error < StandardError; end
|
5
6
|
|
6
7
|
class RuntimeError < Error; end
|
@@ -14,6 +15,5 @@ module JMESPath
|
|
14
15
|
class InvalidArityError < Error; end
|
15
16
|
|
16
17
|
class UnknownFunctionError < Error; end
|
17
|
-
|
18
18
|
end
|
19
19
|
end
|
data/lib/jmespath/lexer.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'json'
|
2
3
|
require 'set'
|
3
4
|
|
4
5
|
module JMESPath
|
5
6
|
# @api private
|
6
7
|
class Lexer
|
7
|
-
|
8
8
|
T_DOT = :dot
|
9
9
|
T_STAR = :star
|
10
10
|
T_COMMA = :comma
|
@@ -134,14 +134,14 @@ module JMESPath
|
|
134
134
|
'w' => STATE_IDENTIFIER,
|
135
135
|
'x' => STATE_IDENTIFIER,
|
136
136
|
'y' => STATE_IDENTIFIER,
|
137
|
-
'z' => STATE_IDENTIFIER
|
138
|
-
}
|
137
|
+
'z' => STATE_IDENTIFIER
|
138
|
+
}.freeze
|
139
139
|
|
140
140
|
VALID_IDENTIFIERS = Set.new(%w(
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
141
|
+
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
|
142
|
+
a b c d e f g h i j k l m n o p q r s t u v w x y z
|
143
|
+
_ 0 1 2 3 4 5 6 7 8 9
|
144
|
+
))
|
145
145
|
|
146
146
|
NUMBERS = Set.new(%w(0 1 2 3 4 5 6 7 8 9))
|
147
147
|
|
@@ -155,13 +155,12 @@ module JMESPath
|
|
155
155
|
'(' => T_LPAREN,
|
156
156
|
')' => T_RPAREN,
|
157
157
|
'{' => T_LBRACE,
|
158
|
-
'}' => T_RBRACE
|
159
|
-
}
|
158
|
+
'}' => T_RBRACE
|
159
|
+
}.freeze
|
160
160
|
|
161
161
|
# @param [String<JMESPath>] expression
|
162
162
|
# @return [Array<Hash>]
|
163
163
|
def tokenize(expression)
|
164
|
-
|
165
164
|
tokens = []
|
166
165
|
chars = CharacterStream.new(expression.chars.to_a)
|
167
166
|
|
@@ -253,7 +252,7 @@ module JMESPath
|
|
253
252
|
tokens << match_or(chars, '&', '&', T_AND, T_EXPREF)
|
254
253
|
when STATE_NOT
|
255
254
|
# consume not equals
|
256
|
-
tokens << match_or(chars, '!', '=', T_COMPARATOR, T_NOT)
|
255
|
+
tokens << match_or(chars, '!', '=', T_COMPARATOR, T_NOT)
|
257
256
|
else
|
258
257
|
# either '<' or '>'
|
259
258
|
# consume less than and greater than
|
@@ -321,11 +320,9 @@ module JMESPath
|
|
321
320
|
# if we have to wrap scalar JSON values to parse them or not.
|
322
321
|
# @api private
|
323
322
|
def self.requires_wrapping?
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
true
|
328
|
-
end
|
323
|
+
JSON.parse('false')
|
324
|
+
rescue JSON::ParserError
|
325
|
+
true
|
329
326
|
end
|
330
327
|
|
331
328
|
if requires_wrapping?
|
@@ -351,7 +348,11 @@ module JMESPath
|
|
351
348
|
if quoted
|
352
349
|
token.value = JSON.parse(token.value)
|
353
350
|
else
|
354
|
-
token.value =
|
351
|
+
token.value = begin
|
352
|
+
JSON.parse(token.value)
|
353
|
+
rescue
|
354
|
+
JSON.parse(sprintf('"%s"', token.value.lstrip))
|
355
|
+
end
|
355
356
|
end
|
356
357
|
rescue JSON::ParserError
|
357
358
|
token.type = T_UNKNOWN
|
@@ -361,7 +362,6 @@ module JMESPath
|
|
361
362
|
end
|
362
363
|
|
363
364
|
class CharacterStream
|
364
|
-
|
365
365
|
def initialize(chars)
|
366
366
|
@chars = chars
|
367
367
|
@position = 0
|
@@ -376,10 +376,7 @@ module JMESPath
|
|
376
376
|
@chars[@position]
|
377
377
|
end
|
378
378
|
|
379
|
-
|
380
|
-
@position
|
381
|
-
end
|
382
|
-
|
379
|
+
attr_reader :position
|
383
380
|
end
|
384
381
|
end
|
385
382
|
end
|
data/lib/jmespath/nodes/and.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module JMESPath
|
2
3
|
module Nodes
|
3
4
|
class And < Node
|
4
|
-
|
5
5
|
def initialize(left, right)
|
6
6
|
@left = left
|
7
7
|
@right = right
|
@@ -19,7 +19,6 @@ module JMESPath
|
|
19
19
|
def optimize
|
20
20
|
self.class.new(@left.optimize, @right.optimize)
|
21
21
|
end
|
22
|
-
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module JMESPath
|
2
3
|
# @api private
|
3
4
|
module Nodes
|
@@ -35,7 +36,7 @@ module JMESPath
|
|
35
36
|
|
36
37
|
private
|
37
38
|
|
38
|
-
def check(
|
39
|
+
def check(_left_value, _right_value)
|
39
40
|
nil
|
40
41
|
end
|
41
42
|
|
@@ -47,7 +48,6 @@ module JMESPath
|
|
47
48
|
end
|
48
49
|
|
49
50
|
module Comparators
|
50
|
-
|
51
51
|
class Eq < Comparator
|
52
52
|
def check(left_value, right_value)
|
53
53
|
Util.as_json(left_value) == Util.as_json(right_value)
|
@@ -62,41 +62,25 @@ module JMESPath
|
|
62
62
|
|
63
63
|
class Gt < Comparator
|
64
64
|
def check(left_value, right_value)
|
65
|
-
if comparable?(left_value, right_value)
|
66
|
-
left_value > right_value
|
67
|
-
else
|
68
|
-
nil
|
69
|
-
end
|
65
|
+
left_value > right_value if comparable?(left_value, right_value)
|
70
66
|
end
|
71
67
|
end
|
72
68
|
|
73
69
|
class Gte < Comparator
|
74
70
|
def check(left_value, right_value)
|
75
|
-
if comparable?(left_value, right_value)
|
76
|
-
left_value >= right_value
|
77
|
-
else
|
78
|
-
nil
|
79
|
-
end
|
71
|
+
left_value >= right_value if comparable?(left_value, right_value)
|
80
72
|
end
|
81
73
|
end
|
82
74
|
|
83
75
|
class Lt < Comparator
|
84
76
|
def check(left_value, right_value)
|
85
|
-
if comparable?(left_value, right_value)
|
86
|
-
left_value < right_value
|
87
|
-
else
|
88
|
-
nil
|
89
|
-
end
|
77
|
+
left_value < right_value if comparable?(left_value, right_value)
|
90
78
|
end
|
91
79
|
end
|
92
80
|
|
93
81
|
class Lte < Comparator
|
94
82
|
def check(left_value, right_value)
|
95
|
-
if comparable?(left_value, right_value)
|
96
|
-
left_value <= right_value
|
97
|
-
else
|
98
|
-
nil
|
99
|
-
end
|
83
|
+
left_value <= right_value if comparable?(left_value, right_value)
|
100
84
|
end
|
101
85
|
end
|
102
86
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module JMESPath
|
2
3
|
# @api private
|
3
4
|
module Nodes
|
@@ -27,7 +28,7 @@ module JMESPath
|
|
27
28
|
|
28
29
|
class ComparatorCondition < Node
|
29
30
|
COMPARATOR_TO_CONDITION = {}
|
30
|
-
COMPARABLE_TYPES = [
|
31
|
+
COMPARABLE_TYPES = [Numeric, String].freeze
|
31
32
|
|
32
33
|
def initialize(left, right, child)
|
33
34
|
@left = left
|
@@ -35,7 +36,7 @@ module JMESPath
|
|
35
36
|
@child = child
|
36
37
|
end
|
37
38
|
|
38
|
-
def visit(
|
39
|
+
def visit(_value)
|
39
40
|
nil
|
40
41
|
end
|
41
42
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module JMESPath
|
2
3
|
# @api private
|
3
4
|
module Nodes
|
@@ -8,7 +9,7 @@ module JMESPath
|
|
8
9
|
@expression = expression
|
9
10
|
end
|
10
11
|
|
11
|
-
def visit(
|
12
|
+
def visit(_value)
|
12
13
|
self
|
13
14
|
end
|
14
15
|
|
@@ -22,4 +23,3 @@ module JMESPath
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
25
|
-
|
data/lib/jmespath/nodes/field.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module JMESPath
|
2
3
|
# @api private
|
3
4
|
module Nodes
|
@@ -41,9 +42,7 @@ module JMESPath
|
|
41
42
|
def initialize(keys)
|
42
43
|
@keys = keys
|
43
44
|
@key_syms = keys.each_with_object({}) do |k, syms|
|
44
|
-
if k.respond_to?(:to_sym)
|
45
|
-
syms[k] = k.to_sym
|
46
|
-
end
|
45
|
+
syms[k] = k.to_sym if k.respond_to?(:to_sym)
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
@@ -70,10 +69,7 @@ module JMESPath
|
|
70
69
|
|
71
70
|
private
|
72
71
|
|
73
|
-
|
74
|
-
@keys
|
75
|
-
end
|
76
|
-
|
72
|
+
attr_reader :keys
|
77
73
|
end
|
78
74
|
end
|
79
75
|
end
|