Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtaining the complete path / pointer in current context #324

Open
candicerimba opened this issue Feb 7, 2024 · 3 comments
Open

Obtaining the complete path / pointer in current context #324

candicerimba opened this issue Feb 7, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@candicerimba
Copy link

Is there a function we could use to access the complete path / pointer in a current context?

{
   "data": [
        {
            "field": "a",
            "value": "b"
         },
         {
            "field": "a",
            "value": "b" // access the complete path here, as something like /data/0/value
         },
}
@larsga larsga added the enhancement New feature or request label Feb 7, 2024
@larsga
Copy link
Collaborator

larsga commented Feb 7, 2024

There is no such function at the moment, no.

How are you proposing that it would work? What is the argument to the function?

What would you use it for?

@candicerimba
Copy link
Author

I don't think we'd be able to implement it as a function? It feels like it'd require something deeper in the code, kind of how we access .field, we'd be tracking the parent .fields traversed up until that point. I haven't read JSLT code at all, so this might be wholly impossible to do.

We're currently using JSLT to detect certain fields / data, but the action we need to take doesn't happen with JSLT, so we'd ideally want to return a path / pointer to that entry for easy access.

@larsga
Copy link
Collaborator

larsga commented Feb 8, 2024

Yes, it looks awkward to do as a function. One problem is that Jackson's JsonNode doesn't have any way to get the parent of the node, so taking a value and returning a JSLT expression to produce is not straightforward.

It probably is possible to extend the JSLT implementation to track the path taken down to the current value, by creating an ExecutionContext or something like that. It might not always yield correct results, however, and there would be a performance penalty to be paid by all JSLT users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants