JSONPath Support
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:
- Use double quotes to quote text inside JSONPath expressions.
- 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 result object is printed as its String() function.
Given the JSON input:
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:
JSONPath regular expressions are not supported. If you want to match using regular expressions, you can use a tool such as jq
.