openrewrite / openrewrite/rewrite

Uniform JsonPath Yaml matching

Open
#5,437 1 comment 0 reactions 1 assignee View on GitHub

@Jenson3210 is already working on this.

Since May 16, 2025.

discovery enhancement
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.key as a whole
  • group.subgroup and a sublevel key
  • group and a sublevel subgroup.key
  • group, subgroup and key all 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 a CombinedKey that wraps other YamlKey instances in order to be able to flatten to the exact keypath to the entry instead of parsing .'s in these keys as a single Scalar value.
    • 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.