Skip to content

Commit 270a071

Browse files
authored
Merge pull request #40836 from iyear/feat/jsonpath-escape-dot
kubectl/jsonpath: add example of escaping termination character
2 parents 5b3dd1a + d9ef7b3 commit 270a071

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

content/en/docs/reference/kubectl/jsonpath.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ Given the JSON input:
3434
"items":[
3535
{
3636
"kind":"None",
37-
"metadata":{"name":"127.0.0.1"},
37+
"metadata":{
38+
"name":"127.0.0.1",
39+
"labels":{
40+
"kubernetes.io/hostname":"127.0.0.1"
41+
}
42+
},
3843
"status":{
3944
"capacity":{"cpu":"4"},
4045
"addresses":[{"type": "LegacyHostIP", "address":"127.0.0.1"}]
@@ -65,18 +70,19 @@ Given the JSON input:
6570
}
6671
```
6772

68-
Function | Description | Example | Result
69-
--------------------|---------------------------|-----------------------------------------------------------------|------------------
70-
`text` | the plain text | `kind is {.kind}` | `kind is List`
71-
`@` | the current object | `{@}` | the same as input
72-
`.` or `[]` | child operator | `{.kind}`, `{['kind']}` or `{['name\.type']}` | `List`
73-
`..` | recursive descent | `{..name}` | `127.0.0.1 127.0.0.2 myself e2e`
74-
`*` | wildcard. Get all objects | `{.items[*].metadata.name}` | `[127.0.0.1 127.0.0.2]`
75-
`[start:end:step]` | subscript operator | `{.users[0].name}` | `myself`
76-
`[,]` | union operator | `{.items[*]['metadata.name', 'status.capacity']}` | `127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]`
77-
`?()` | filter | `{.users[?(@.name=="e2e")].user.password}` | `secret`
78-
`range`, `end` | iterate list | `{range .items[*]}[{.metadata.name}, {.status.capacity}] {end}` | `[127.0.0.1, map[cpu:4]] [127.0.0.2, map[cpu:8]]`
79-
`''` | quote interpreted string | `{range .items[*]}{.metadata.name}{'\t'}{end}` | `127.0.0.1 127.0.0.2`
73+
Function | Description | Example | Result
74+
--------------------|------------------------------|-----------------------------------------------------------------|------------------
75+
`text` | the plain text | `kind is {.kind}` | `kind is List`
76+
`@` | the current object | `{@}` | the same as input
77+
`.` or `[]` | child operator | `{.kind}`, `{['kind']}` or `{['name\.type']}` | `List`
78+
`..` | recursive descent | `{..name}` | `127.0.0.1 127.0.0.2 myself e2e`
79+
`*` | wildcard. Get all objects | `{.items[*].metadata.name}` | `[127.0.0.1 127.0.0.2]`
80+
`[start:end:step]` | subscript operator | `{.users[0].name}` | `myself`
81+
`[,]` | union operator | `{.items[*]['metadata.name', 'status.capacity']}` | `127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]`
82+
`?()` | filter | `{.users[?(@.name=="e2e")].user.password}` | `secret`
83+
`range`, `end` | iterate list | `{range .items[*]}[{.metadata.name}, {.status.capacity}] {end}` | `[127.0.0.1, map[cpu:4]] [127.0.0.2, map[cpu:8]]`
84+
`''` | quote interpreted string | `{range .items[*]}{.metadata.name}{'\t'}{end}` | `127.0.0.1 127.0.0.2`
85+
`\` | escape termination character | `{.items[0].metadata.labels.kubernetes\.io/hostname}` | `127.0.0.1`
8086

8187
Examples using `kubectl` and JSONPath expressions:
8288

@@ -87,6 +93,7 @@ kubectl get pods -o=jsonpath='{.items[0]}'
8793
kubectl get pods -o=jsonpath='{.items[0].metadata.name}'
8894
kubectl get pods -o=jsonpath="{.items[*]['metadata.name', 'status.capacity']}"
8995
kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.startTime}{"\n"}{end}'
96+
kubectl get pods -o=jsonpath='{.items[0].metadata.labels.kubernetes\.io/hostname}'
9097
```
9198

9299
{{< note >}}

0 commit comments

Comments
 (0)