Update Chinese page jsonpath
This commit is contained in:
@@ -3,7 +3,7 @@ title: JSONPath 支持
|
|||||||
content_type: concept
|
content_type: concept
|
||||||
weight: 25
|
weight: 25
|
||||||
---
|
---
|
||||||
<!--
|
<!--
|
||||||
---
|
---
|
||||||
title: JSONPath Support
|
title: JSONPath Support
|
||||||
content_type: concept
|
content_type: concept
|
||||||
@@ -13,34 +13,34 @@ weight: 25
|
|||||||
|
|
||||||
<!-- overview -->
|
<!-- overview -->
|
||||||
<!--
|
<!--
|
||||||
Kubectl supports JSONPath template.
|
Kubectl supports JSONPath template.
|
||||||
-->
|
-->
|
||||||
Kubectl 支持 JSONPath 模板。
|
Kubectl 支持 JSONPath 模板。
|
||||||
|
|
||||||
|
|
||||||
<!-- body -->
|
<!-- body -->
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
JSONPath template is composed of JSONPath expressions enclosed by curly braces {}.
|
JSONPath template is composed of JSONPath expressions enclosed by curly braces {}.
|
||||||
Kubectl uses JSONPath expressions to filter on specific fields in the JSON object and format the output.
|
Kubectl uses JSONPath expressions to filter on specific fields in the JSON object and format the output.
|
||||||
In addition to the original JSONPath template syntax, the following functions and syntax are valid:
|
In addition to the original JSONPath template syntax, the following functions and syntax are valid:
|
||||||
-->
|
-->
|
||||||
JSONPath 模板由 {} 包起来的 JSONPath 表达式组成。Kubectl 使用 JSONPath 表达式来过滤 JSON 对象中的特定字段并格式化输出。除了原始的 JSONPath 模板语法,以下函数和语法也是有效的:
|
JSONPath 模板由 {} 包起来的 JSONPath 表达式组成。Kubectl 使用 JSONPath 表达式来过滤 JSON 对象中的特定字段并格式化输出。除了原始的 JSONPath 模板语法,以下函数和语法也是有效的:
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
1. Use double quotes to quote text inside JSONPath expressions.
|
1. Use double quotes to quote text inside JSONPath expressions.
|
||||||
2. Use the `range`, `end` operators to iterate lists.
|
2. Use the `range`, `end` operators to iterate lists.
|
||||||
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`.
|
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`.
|
||||||
-->
|
-->
|
||||||
1. 使用双引号将 JSONPath 表达式内的文本引起来。
|
1. 使用双引号将 JSONPath 表达式内的文本引起来。
|
||||||
2. 使用 `range`,`end` 运算符来迭代列表。
|
2. 使用 `range`,`end` 运算符来迭代列表。
|
||||||
3. 使用负片索引后退列表。负索引不会“环绕”列表,并且只要 `-index + listLength> = 0` 就有效。
|
3. 使用负片索引后退列表。负索引不会“环绕”列表,并且只要 `-index + listLength> = 0` 就有效。
|
||||||
|
|
||||||
{{< note >}}
|
{{< note >}}
|
||||||
<!--
|
<!--
|
||||||
- The `$` operator is optional since the expression always starts from the root object by default.
|
- The `$` operator is optional since the expression always starts from the root object by default.
|
||||||
|
|
||||||
- The result object is printed as its String() function.
|
- The result object is printed as its String() function.
|
||||||
-->
|
-->
|
||||||
- `$` 运算符是可选的,因为默认情况下表达式总是从根对象开始。
|
- `$` 运算符是可选的,因为默认情况下表达式总是从根对象开始。
|
||||||
|
|
||||||
@@ -48,8 +48,8 @@ JSONPath 模板由 {} 包起来的 JSONPath 表达式组成。Kubectl 使用 JSO
|
|||||||
|
|
||||||
{{< /note >}}
|
{{< /note >}}
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Given the JSON input:
|
Given the JSON input:
|
||||||
-->
|
-->
|
||||||
给定 JSON 输入:
|
给定 JSON 输入:
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ Given the JSON input:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Function | Description | Example | Result
|
Function | Description | Example | Result
|
||||||
--------------------|---------------------------|-----------------------------------------------------------------|------------------
|
--------------------|---------------------------|-----------------------------------------------------------------|------------------
|
||||||
`text` | the plain text | `kind is {.kind}` | `kind is List`
|
`text` | the plain text | `kind is {.kind}` | `kind is List`
|
||||||
@@ -102,7 +102,7 @@ Function | Description | Example
|
|||||||
`[,]` | union operator | `{.items[*]['metadata.name', 'status.capacity']}` | `127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]`
|
`[,]` | union operator | `{.items[*]['metadata.name', 'status.capacity']}` | `127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]`
|
||||||
`?()` | filter | `{.users[?(@.name=="e2e")].user.password}` | `secret`
|
`?()` | filter | `{.users[?(@.name=="e2e")].user.password}` | `secret`
|
||||||
`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]]`
|
`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]]`
|
||||||
`''` | quote interpreted string | `{range .items[*]}{.metadata.name}{'\t'}{end}` | `127.0.0.1 127.0.0.2`
|
`''` | quote interpreted string | `{range .items[*]}{.metadata.name}{'\t'}{end}` | `127.0.0.1 127.0.0.2`
|
||||||
-->
|
-->
|
||||||
函数 | 描述 | 示例 | 结果
|
函数 | 描述 | 示例 | 结果
|
||||||
--------------------|---------------------------|-----------------------------------------------------------------|------------------
|
--------------------|---------------------------|-----------------------------------------------------------------|------------------
|
||||||
@@ -117,8 +117,8 @@ Function | Description | Example
|
|||||||
`range`, `end` | 迭代列表 | `{range .items[*]}[{.metadata.name}, {.status.capacity}] {end}` | `[127.0.0.1, map[cpu:4]] [127.0.0.2, map[cpu:8]]`
|
`range`, `end` | 迭代列表 | `{range .items[*]}[{.metadata.name}, {.status.capacity}] {end}` | `[127.0.0.1, map[cpu:4]] [127.0.0.2, map[cpu:8]]`
|
||||||
`''` | 引用解释执行字符串 | `{range .items[*]}{.metadata.name}{'\t'}{end}` | `127.0.0.1 127.0.0.2`
|
`''` | 引用解释执行字符串 | `{range .items[*]}{.metadata.name}{'\t'}{end}` | `127.0.0.1 127.0.0.2`
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Examples using `kubectl` and JSONPath expressions:
|
Examples using `kubectl` and JSONPath expressions:
|
||||||
-->
|
-->
|
||||||
使用 `kubectl` 和 JSONPath 表达式的示例:
|
使用 `kubectl` 和 JSONPath 表达式的示例:
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ kubectl get pods -o=jsonpath="{.items[*]['metadata.name', 'status.capacity']}"
|
|||||||
kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.startTime}{"\n"}{end}'
|
kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.startTime}{"\n"}{end}'
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
{{< note >}}
|
{{< note >}}
|
||||||
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:
|
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:
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{\"\t\"}{.status.
|
|||||||
{{< /note >}}
|
{{< /note >}}
|
||||||
-->
|
-->
|
||||||
{{< note >}}
|
{{< note >}}
|
||||||
在 Windows 上,您必须用双引号把任何包含空格的 JSONPath 模板(不是上面 bash 所示的单引号)。
|
在 Windows 上,对于任何包含空格的 JSONPath 模板,您必须使用双引号(不是上面 bash 所示的单引号)。
|
||||||
反过来,这意味着您必须在模板中的所有文字周围使用单引号或转义的双引号。
|
反过来,这意味着您必须在模板中的所有文字周围使用单引号或转义的双引号。
|
||||||
例如:
|
例如:
|
||||||
|
|
||||||
@@ -176,4 +176,3 @@ kubectl get pods -o jsonpath='{.items[?(@.metadata.name=~/^test$/)].metadata.nam
|
|||||||
kubectl get pods -o json | jq -r '.items[] | select(.metadata.name | test("test-")).spec.containers[].image'
|
kubectl get pods -o json | jq -r '.items[] | select(.metadata.name | test("test-")).spec.containers[].image'
|
||||||
```
|
```
|
||||||
{{< /note >}}
|
{{< /note >}}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user