Skip to content

Expose more path fragment operations to public API#1069

Open
jdimeo wants to merge 1 commit intojson-path:masterfrom
jdimeo:master
Open

Expose more path fragment operations to public API#1069
jdimeo wants to merge 1 commit intojson-path:masterfrom
jdimeo:master

Conversation

@jdimeo
Copy link

@jdimeo jdimeo commented Feb 17, 2026

JsonPath does not create intermediary objects/paths as discussed in #256 , and it shouldn't. However, if you want to do this yourself, very helpful aspects of the JsonPath API are marked as private/protected.

One operation that I was surprised to see was quite difficult was to evaluate a JsonPath at the "immediate parent", something like root -> tail -> previous.

I was able to achieve this using hacky reflection, so this PR opening up the APIs I needed to call with forced reflection access.

  1. PathToken.getPathFragment seems like the most obvious- the abstract class marks it as protected but all child implementing classes are public. Not sure why it's protected.
  2. PathToken.getPrevoius is already available as prev() but it's package-private. If we're willing to expose getNext why not getPrev?
  3. Instantiating intermediary objects through arrays require knowing what index we're on, so ArrayIndexToken.getIndexes gives a mechanism for that without exposing the entire ArrayIndexOperation. This doesn't support slicing, but since it's just a simple getter, it's not promising full support or new functionality.
  4. The most controversial one is likely my getPathImpl. This is the entry point to all these helpful path fragment/path token APIs from a JsonPath but I understand how it's confusing with String getPath and might be something you don't want to expose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments