0
# Core Expressions
1
2
Fundamental expression types that form the building blocks of JMESPath queries. These expressions handle basic JSON navigation, field access, literals, and compound operations.
3
4
## Capabilities
5
6
### Field Access Expression
7
8
Accesses a field from a JSON object using field names. Supports camelCase conversion for compatibility.
9
10
```java { .api }
11
public class JmesPathField implements JmesPathExpression {
12
/**
13
* Creates a field access expression for the specified field name
14
* @param value The field name to access
15
*/
16
public JmesPathField(String value);
17
18
/**
19
* Gets the field name being accessed
20
* @return The field name
21
*/
22
public String getValue();
23
24
public <Input, Output> Output accept(JmesPathVisitor<Input, Output> visitor, Input input)
25
throws InvalidTypeException;
26
}
27
```
28
29
**Usage Example:**
30
31
```java
32
// Access "name" field from JSON object
33
JmesPathField nameField = new JmesPathField("name");
34
JsonNode result = nameField.accept(visitor, jsonObject);
35
```
36
37
### Identity Expression
38
39
Returns the current JSON node unchanged. Used as a placeholder or base for other operations.
40
41
```java { .api }
42
public class JmesPathIdentity implements JmesPathExpression {
43
/**
44
* Creates an identity expression that returns the input unchanged
45
*/
46
public JmesPathIdentity();
47
48
public <Input, Output> Output accept(JmesPathVisitor<Input, Output> visitor, Input input)
49
throws InvalidTypeException;
50
}
51
```
52
53
**Usage Example:**
54
55
```java
56
// Identity expression - returns input as-is
57
JmesPathIdentity identity = new JmesPathIdentity();
58
JsonNode result = identity.accept(visitor, inputData);
59
```
60
61
### Literal Expression
62
63
Represents literal JSON values (strings, numbers, booleans, objects, arrays) within expressions.
64
65
```java { .api }
66
public class JmesPathLiteral implements JmesPathExpression {
67
/**
68
* Creates a literal expression from a string value
69
* @param value The literal string value
70
*/
71
public JmesPathLiteral(String value);
72
73
/**
74
* Creates a literal expression from a JsonNode value
75
* @param value The literal JsonNode value
76
*/
77
public JmesPathLiteral(JsonNode value);
78
79
/**
80
* Gets the literal value as a JsonNode
81
* @return The JsonNode representation of the literal
82
*/
83
public JsonNode getValue();
84
85
public <Input, Output> Output accept(JmesPathVisitor<Input, Output> visitor, Input input)
86
throws InvalidTypeException;
87
}
88
```
89
90
**Usage Example:**
91
92
```java
93
// Create literal values
94
JmesPathLiteral stringLiteral = new JmesPathLiteral("hello");
95
JmesPathLiteral numberLiteral = new JmesPathLiteral(mapper.valueToTree(42));
96
```
97
98
### Sub-Expression (Chained Access)
99
100
Chains multiple expressions together, evaluating them in sequence where each result becomes the input for the next expression.
101
102
```java { .api }
103
public class JmesPathSubExpression implements JmesPathExpression {
104
/**
105
* Creates a sub-expression from individual expressions
106
* @param expressions Variable number of expressions to chain
107
*/
108
public JmesPathSubExpression(JmesPathExpression... expressions);
109
110
/**
111
* Creates a sub-expression from a list of expressions
112
* @param expressions List of expressions to chain
113
*/
114
public JmesPathSubExpression(List<JmesPathExpression> expressions);
115
116
/**
117
* Gets the list of chained expressions
118
* @return List of expressions in evaluation order
119
*/
120
public List<JmesPathExpression> getExpressions();
121
122
public <Input, Output> Output accept(JmesPathVisitor<Input, Output> visitor, Input input)
123
throws InvalidTypeException;
124
}
125
```
126
127
**Usage Example:**
128
129
```java
130
// Chain expressions: user.profile.name
131
JmesPathSubExpression chainedAccess = new JmesPathSubExpression(
132
new JmesPathField("user"),
133
new JmesPathField("profile"),
134
new JmesPathField("name")
135
);
136
JsonNode result = chainedAccess.accept(visitor, data);
137
```
138
139
### Multi-Select List Expression
140
141
Creates an array by evaluating multiple expressions against the same input and collecting their results.
142
143
```java { .api }
144
public class JmesPathMultiSelectList implements JmesPathExpression {
145
/**
146
* Creates a multi-select list from individual expressions
147
* @param expressions Variable number of expressions to evaluate
148
*/
149
public JmesPathMultiSelectList(JmesPathExpression... expressions);
150
151
/**
152
* Creates a multi-select list from a list of expressions
153
* @param expressions List of expressions to evaluate
154
*/
155
public JmesPathMultiSelectList(List<JmesPathExpression> expressions);
156
157
/**
158
* Gets the list of expressions to evaluate
159
* @return List of expressions
160
*/
161
public List<JmesPathExpression> getExpressions();
162
163
public <Input, Output> Output accept(JmesPathVisitor<Input, Output> visitor, Input input)
164
throws InvalidTypeException;
165
}
166
```
167
168
**Usage Example:**
169
170
```java
171
// Multi-select: [name, age, email]
172
JmesPathMultiSelectList multiSelect = new JmesPathMultiSelectList(
173
new JmesPathField("name"),
174
new JmesPathField("age"),
175
new JmesPathField("email")
176
);
177
JsonNode result = multiSelect.accept(visitor, userObject);
178
// Result: ["Alice", 30, "alice@example.com"]
179
```
180
181
## Type Definitions
182
183
### Visitor Interface
184
185
```java { .api }
186
public interface JmesPathVisitor<Input, Output> {
187
Output visit(JmesPathField fieldNode, Input input);
188
Output visit(JmesPathIdentity jmesPathIdentity, Input input);
189
Output visit(JmesPathLiteral literal, Input input);
190
Output visit(JmesPathSubExpression subExpression, Input input) throws InvalidTypeException;
191
Output visit(JmesPathMultiSelectList multiSelectList, Input input) throws InvalidTypeException;
192
Output visit(JmesPathProjection jmesPathProjection, Input input) throws InvalidTypeException;
193
Output visit(JmesPathValueProjection valueProjection, Input input) throws InvalidTypeException;
194
Output visit(JmesPathFlatten flatten, Input input) throws InvalidTypeException;
195
Output visit(JmesPathFunction function, Input input) throws InvalidTypeException;
196
Output visit(JmesPathFilter filter, Input input) throws InvalidTypeException;
197
Output visit(Comparator op, Input input) throws InvalidTypeException;
198
Output visit(JmesPathNotExpression expression, Input input) throws InvalidTypeException;
199
Output visit(JmesPathAndExpression expression, Input input) throws InvalidTypeException;
200
}
201
```