JsonPathMatcher
and JsonPath
expressions may be used in other markup languages besides JSON which support it, such as YAML. When we refer to "JSON" keep in mind JsonPathMatcher and JsonPath expressions apply to markup languages which have a JsonPathMatcher implementation, such as YAML.JsonPathMatcher
provides methods for matching the given cursor location using a provided JsonPath
expression. "JsonPath" (sometimes stylized as JSONPath) is a query language for JSON, similar to how XPath is a query language for XML. Despite the name, JsonPathMatcher can be used on other languages besides JSON, such as YAML.$
.property
['property']
A..Za..z_
.[n]
[:n]
..property
*
address.*
means all properties of the address
object, and book[*]
means all items of the book
array.[(expression)]
@
[?(@.kind == 'ServiceAccount')]
is the actual filter expression, and @
represents the current item being processed.==
[?(@.kind == 'Deployment')]
.=~
[?(@.uses =~ 'actions/[email protected]*')]
matches items which uses
starts with actions/[email protected]
, and so would include actions/[email protected]
.org.openrewrite.json.JsonPathMatcher
(or org.openrewrite.yaml.JsonPathMatcher
) are the classes that most recipes will use JsonPath expression patterns with. Instances are created by providing the JsonPath expression pattern to the JsonPathMatcher constructor:Cursor
at a point within the tree matches what you're looking for.JsonPathMatcher.matches(Cursor c)
returns true
if the provided Cursor
is a location within the document tree which exactly matches the provided JsonPath expression. JsonPathMatcher.encloses(Cursor c)
returns true
if the provided Cursor
is a location within the document tree which is within the path of the provided JsonPath expression.