Closed paulo-raca closed 1 year ago
I'm not sure either of the proposed solutions solves the issue. If I can summarize, you would like a set of modifications that to be applied in arbitrary order and are looking for a way to specify the desired order. It seems like the simple solution is to just apply the modification in the desired order. I'm probably missing some key part of this. I apologize if I missed the point.
Is this a dead issue?
Hello, and thank you for this great library!
I'm trying to apply multiple JSONPaths in a JSON and I'm having a few difficulties, please help me out
Thanks a lot!
Use case
I'm using multiple JSONPaths to select/deselect parts of my datastructure that need processing (modifying, filtering, etc).
It basically looks like this:
When it runs, it wraps all the matched JSON subtrees in "tags" that tells whenever that subtree is enabled or disabled:
For instance, I use it like this:
Problem
My current implementation uses
jp.Expr.Modify()
serially to add tags:Unfortunately, since it modifies the data at each step, the processing order affects the output.
E.g., if
$.a.b
is executed before$.a
both subtrees are tagged. However if the order is reversed,$.a
is tagged, but$.a.b
(since.b
won't match the JsonFilterTag)Possible Solutions
I can think of 2 ways to work around this issue, and either one works fine with me. Or maybe there is something else I'm missing?
Supporting "Tag" objects:
Everything would work for me if JSONPath somehow ignored
JsonPathSelectorTag
. It seems reasonably to add a special structure where I can attach arbitrary data and that is also ignored by JsonPathThis maps very well with my current implementation and seems easier to implement in the library
Supporting operations on multiple paths simultaneously
This seems a bit more complicate to implement, but also more flexible. Note that
Modify()
would need an extra argument to specify which expressions matched each element.