openrewrite / openrewrite/rewrite
Uniform JsonPath Yaml matching
@Jenson3210 is already working on this.
Since May 16, 2025.
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 570
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
What problem are you trying to solve?
For the JsonPathMatcher on yaml, past few days I've already seen multiple issues/questions popping up from various angles.
Root cause of these issues that I have been involved in was caused by the fact that while comparing the jsonpath with the key, these keys might be occuring in multiple different ways.
eg. The group.subgroup.key can be written in yaml in 4 ways:
group.subgroup.keyas a wholegroup.subgroupand a sublevelkeygroupand a sublevelsubgroup.keygroup,subgroupandkeyall 3 in separate levels.
The json pathMatcher works with Yaml.MappingEntry keys. These keys will be the exact string as they are in the file (hence, can be 2 yaml 'levels')
This causes the pathMatcher to behave differently when analyzing these different notations although semantically they are the same.
Describe the solution you'd like
We could (I will keep this list up to date based on the replies given here so that we can come to a best solution):
During parsing have aCombinedKeythat wraps otherYamlKeyinstances in order to be able to flatten to the exact keypath to the entry instead of parsing.'s in these keys as a singleScalarvalue.Broader impact compared to the other solutions- The yaml spec does not forbid
.in keys as long as the key is unique.
- During matching of the path, always flatter the yamlDocument to a single structure
- We have a uniform behaviour for all pathMatching operations
- Also quite expensive on performance to just always flatten even for files that won't match the matcher.
Have you considered any alternatives or workarounds?
... Other ideas/opinions are welcomed!
Additional context
- Due to
.being allowed in the key but lots of frameworks using it as a split, the behaviour of this splitting should at least be choice of the consumer.
Are you interested in contributing this feature to OpenRewrite?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.