clean-up jsonpath additional functions list (#11027)

This commit is contained in:
Karen Bradshaw
2018-11-18 21:27:56 -05:00
committed by k8s-ci-robot
parent 4f6f159dcb
commit 9b1d77e07f
+26 -10
View File
@@ -1,18 +1,32 @@
--- ---
title: JSONPath Support title: JSONPath Support
content_template: templates/concept
weight: 25
--- ---
JSONPath template is composed of JSONPath expressions enclosed by {}. {{% capture overview %}}
And we add three functions in addition to the original JSONPath syntax: Kubectl supports JSONPath template.
{{% /capture %}}
1. The `$` operator is optional since the expression always starts from the root object by default. {{% capture body %}}
2. We can use `""` to quote text inside JSONPath expressions.
3. We can use `range` operator to iterate lists.
4. We can use negative slice indices to step backwards through a list. Negative indices do not "wrap around" a list. They are valid as long as `-index + listLength >= 0`.
The result object is printed as its String() function. 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.
In addition to the original JSONPath template syntax, the following functions and syntax are valid:
Given the input: 1. Use double quotes to quote text inside JSONPath expressions.
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`.
{{< note >}}
- The `$` operator is optional since the expression always starts from the root object by default.
- The result object is printed as its String() function.
{{< /note >}}
Given the JSON input:
```json ```json
{ {
@@ -52,7 +66,7 @@ Given the 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
@ | the current object | {@} | the same as input @ | the current object | {@} | the same as input
. or [] | child operator | {.kind} or {['kind']} | List . or [] | child operator | {.kind} or {['kind']} | List
@@ -64,7 +78,7 @@ text | the plain text | kind is {.kind} | kind is List
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
Below are some examples using jsonpath: Examples using `kubectl` and JSONPath expressions:
```shell ```shell
$ kubectl get pods -o json $ kubectl get pods -o json
@@ -80,3 +94,5 @@ On Windows, you must _double_ quote any JSONPath template that contains spaces (
C:\> kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.startTime}{'\n'}{end}" C:\> kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.startTime}{'\n'}{end}"
C:\> kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{\"\t\"}{.status.startTime}{\"\n\"}{end}" C:\> kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{\"\t\"}{.status.startTime}{\"\n\"}{end}"
``` ```
{{% /capture %}}