You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Use double quotes to quote text inside JSONPath expressions.
31
35
2. Use the `range`, `end` operators to iterate lists.
32
-
3. Use negative slice indices to step backwards through a list. Negative indices do not "wrap around" a list and are valid as long as `-index + listLength >= 0`.
36
+
3. Use negative slice indices to step backwards through a list.
37
+
Negative indices do _not_ "wrap around" a list and are valid as long as \\( ( - index + listLength ) \ge 0 \\).
Examples using `kubectl` and JSONPath expressions:
@@ -140,26 +160,27 @@ kubectl get pods -o=jsonpath='{.items[0].metadata.labels.kubernetes\.io/hostname
140
160
141
161
{{< note >}}
142
162
<!--
143
-
On Windows, you must _double_ quote any JSONPath template that contains spaces (not single quote as shown above for bash).
144
-
This in turn means that you must use a single quote or escaped double quote around any literals in the template. For example:
145
-
146
-
```cmd
147
-
kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.startTime}{'\n'}{end}"
148
-
kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{\"\t\"}{.status.startTime}{\"\n\"}{end}"
149
-
```
163
+
On Windows, you must _double_ quote any JSONPath template that contains spaces (not single quote as shown above for bash). This in turn means that you must use a single quote or escaped double quote around any literals in the template. For example:
150
164
-->
151
-
在 Windows 上,对于任何包含空格的 JSONPath 模板,你必须使用双引号(不是上面 bash 所示的单引号)。
165
+
在 Windows 上,对于任何包含空格的 JSONPath 模板,你必须使用**双**引号(不是上面 bash 所示的单引号)。
152
166
反过来,这意味着你必须在模板中的所有文字周围使用单引号或转义的双引号。例如:
153
167
154
168
```cmd
155
-
C:\> kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.startTime}{'\n'}{end}"
156
-
C:\> kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{\"\t\"}{.status.startTime}{\"\n\"}{end}"
169
+
kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.startTime}{'\n'}{end}"
170
+
kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{\"\t\"}{.status.startTime}{\"\n\"}{end}"
157
171
```
158
172
{{< /note >}}
159
173
160
174
<!--
175
+
## Regular expressions in JSONPath
176
+
161
177
JSONPath regular expressions are not supported. If you want to match using regular expressions, you can use a tool such as `jq`.
0 commit comments