0
# Expression Evaluation
1
2
The primary visitor implementation that evaluates JMESPath expressions against JSON data. This is the main execution engine that processes expression trees and returns JSON results.
3
4
## Capabilities
5
6
### Evaluation Visitor
7
8
The concrete visitor implementation that evaluates all expression types against JsonNode input data.
9
10
```java { .api }
11
public class JmesPathEvaluationVisitor implements JmesPathVisitor<JsonNode, JsonNode> {
12
/**
13
* Creates a new evaluation visitor for processing expressions
14
*/
15
public JmesPathEvaluationVisitor();
16
}
17
```
18
19
### Field Access Evaluation
20
21
Retrieves field values from JSON objects with camelCase conversion support.
22
23
```java { .api }
24
public JsonNode visit(JmesPathField fieldNode, JsonNode input) {
25
/**
26
* Evaluates field access on the input JSON node
27
* @param fieldNode The field expression to evaluate
28
* @param input The JSON object to access
29
* @return The field value or null if not found/invalid type
30
*/
31
}
32
```
33
34
**Implementation Details:**
35
- Returns the field value if input is a JSON object
36
- Applies camelCase conversion to field names
37
- Returns `NullNode` if input is not an object or field not found
38
39
### Identity Evaluation
40
41
Returns the input node unchanged.
42
43
```java { .api }
44
public JsonNode visit(JmesPathIdentity jmesPathIdentity, JsonNode input) {
45
/**
46
* Returns the input node as-is
47
* @param jmesPathIdentity The identity expression
48
* @param input The input JSON node
49
* @return The input node unchanged
50
*/
51
}
52
```
53
54
### Literal Evaluation
55
56
Returns the literal value stored in the expression.
57
58
```java { .api }
59
public JsonNode visit(JmesPathLiteral literal, JsonNode input) {
60
/**
61
* Returns the literal value
62
* @param literal The literal expression containing the value
63
* @param input The input JSON node (ignored)
64
* @return The literal value as JsonNode
65
*/
66
}
67
```
68
69
### Sub-Expression Evaluation
70
71
Evaluates chained expressions in sequence, passing results between expressions.
72
73
```java { .api }
74
public JsonNode visit(JmesPathSubExpression subExpression, JsonNode input) throws InvalidTypeException {
75
/**
76
* Evaluates a chain of expressions sequentially
77
* @param subExpression The sub-expression containing chained expressions
78
* @param input The initial input JSON node
79
* @return The result of the final expression in the chain
80
* @throws InvalidTypeException If any expression evaluation fails
81
*/
82
}
83
```
84
85
**Implementation Details:**
86
- Evaluates the first expression against the original input
87
- Each subsequent expression uses the previous result as input
88
- Returns the final result from the last expression
89
90
### Multi-Select List Evaluation
91
92
Evaluates multiple expressions against the same input and returns an array of results.
93
94
```java { .api }
95
public JsonNode visit(JmesPathMultiSelectList multiSelectList, JsonNode input) throws InvalidTypeException {
96
/**
97
* Evaluates multiple expressions and collects results into an array
98
* @param multiSelectList The multi-select expression containing sub-expressions
99
* @param input The input JSON node to evaluate against
100
* @return ArrayNode containing results from all expressions
101
* @throws InvalidTypeException If any expression evaluation fails
102
*/
103
}
104
```
105
106
### Projection Evaluation
107
108
Evaluates list projections by applying an expression to each element of an array.
109
110
```java { .api }
111
public JsonNode visit(JmesPathProjection jmesPathProjection, JsonNode input) throws InvalidTypeException {
112
/**
113
* Evaluates list projection expressions
114
* @param jmesPathProjection The projection expression
115
* @param input The input JSON node
116
* @return ArrayNode with projection results, or NullNode if input not array
117
* @throws InvalidTypeException If expression evaluation fails
118
*/
119
}
120
```
121
122
**Implementation Details:**
123
- Left-hand side creates the array to project over
124
- Right-hand side expression is applied to each array element
125
- Returns `NullNode` if LHS result is not an array
126
- Filters out null results from the projection
127
128
### Value Projection Evaluation
129
130
Evaluates object value projections by creating a list from object values and projecting over them.
131
132
```java { .api }
133
public JsonNode visit(JmesPathValueProjection valueProjection, JsonNode input) throws InvalidTypeException {
134
/**
135
* Evaluates object value projection expressions
136
* @param valueProjection The value projection expression
137
* @param input The input JSON node
138
* @return ArrayNode with projection results, or NullNode if input not object
139
* @throws InvalidTypeException If expression evaluation fails
140
*/
141
}
142
```
143
144
### Filter Evaluation
145
146
Evaluates filter expressions by testing each array element against a condition.
147
148
```java { .api }
149
public JsonNode visit(JmesPathFilter filter, JsonNode input) throws InvalidTypeException {
150
/**
151
* Evaluates filter expressions on arrays
152
* @param filter The filter expression with condition
153
* @param input The input JSON node
154
* @return ArrayNode with filtered results, or NullNode if input not array
155
* @throws InvalidTypeException If expression evaluation fails
156
*/
157
}
158
```
159
160
**Implementation Details:**
161
- LHS expression provides the array to filter
162
- Comparator expression evaluates to boolean for each element
163
- RHS expression is applied to elements that pass the filter
164
- Only elements where comparator returns `BooleanNode.TRUE` are included
165
166
### Logical Operation Evaluation
167
168
Evaluates logical AND and NOT expressions with short-circuit behavior.
169
170
```java { .api }
171
public JsonNode visit(JmesPathAndExpression andExpression, JsonNode input) throws InvalidTypeException {
172
/**
173
* Evaluates logical AND expressions
174
* @param andExpression The AND expression with left and right operands
175
* @param input The input JSON node
176
* @return RHS result if LHS is true, otherwise LHS result
177
* @throws InvalidTypeException If expression evaluation fails
178
*/
179
}
180
181
public JsonNode visit(JmesPathNotExpression notExpression, JsonNode input) throws InvalidTypeException {
182
/**
183
* Evaluates logical NOT expressions
184
* @param notExpression The NOT expression with operand
185
* @param input The input JSON node
186
* @return BooleanNode.TRUE if operand is falsy, BooleanNode.FALSE otherwise
187
* @throws InvalidTypeException If expression evaluation fails
188
*/
189
}
190
```
191
192
### Array Flattening Evaluation
193
194
Flattens nested arrays by one level.
195
196
```java { .api }
197
public JsonNode visit(JmesPathFlatten flatten, JsonNode input) throws InvalidTypeException {
198
/**
199
* Evaluates array flattening expressions
200
* @param flatten The flatten expression
201
* @param input The input JSON node
202
* @return Flattened ArrayNode, or NullNode if input not array
203
* @throws InvalidTypeException If expression evaluation fails
204
*/
205
}
206
```
207
208
**Implementation Details:**
209
- Evaluates the flatten expression to get an array
210
- Iterates through array elements
211
- Non-array elements are added directly
212
- Array elements have their contents added individually
213
- Returns a single flattened array
214
215
### Function Evaluation
216
217
Evaluates function expressions by processing arguments and calling the function's evaluate method.
218
219
```java { .api }
220
public JsonNode visit(JmesPathFunction function, JsonNode input) throws InvalidTypeException {
221
/**
222
* Evaluates function expressions in applicative order
223
* @param function The function expression with arguments
224
* @param input The input JSON node
225
* @return The result of the function evaluation
226
* @throws InvalidTypeException If function evaluation fails
227
*/
228
}
229
```
230
231
**Implementation Details:**
232
- Evaluates all function arguments against the input
233
- Calls the function's `evaluate` method with evaluated arguments
234
- Returns the function's result
235
236
### Comparison Evaluation
237
238
Evaluates comparison expressions by comparing left and right operands.
239
240
```java { .api }
241
public JsonNode visit(Comparator op, JsonNode input) throws InvalidTypeException {
242
/**
243
* Evaluates comparison expressions
244
* @param op The comparison operator
245
* @param input The input JSON node
246
* @return BooleanNode.TRUE if comparison matches, BooleanNode.FALSE otherwise
247
* @throws InvalidTypeException If expression evaluation fails
248
*/
249
}
250
```