Closed xujianjun2000 closed 11 months ago
The only call in jp that provides normalized paths is the jp.Walk()
function.
The only call in jp that provides normalized paths is the
jp.Walk()
function.
Yes,I did see that path in Walk(),but printed path.String(), seems they are not the exact definition in ITEF. Sometimes path.String() gives "dot notation", not always "bracket notation" when represents a Child node.
Below I quote the definition of Normalized Paths in 2.7 section:
2.7. Normalized Paths
A Normalized Path is a unique representation of the location of a node in a value which uniquely identifies the node in the value. Specifically, a Normalized Path is a JSONPath query with restricted syntax (defined below), e.g., $['book'][3], which when applied to the value results in a nodelist consisting of just the node identified by the Normalized Path. Note: a Normalized Path represents the identity of a node in a specific value. There is precisely one Normalized Path identifying any particular node in a value.
A nodelist may be represented compactly in JSON as an array of strings, where the strings are Normalized Paths.
Normalized Paths provide a predictable format that simplifies testing and post-processing of nodelists, e.g., to remove duplicate nodes. Normalized Paths are used in this document as result paths in examples.
Normalized Paths use the canonical bracket notation, rather than dot notation.
I'll have to add an itef string version.
I'll have to add an itef string version.
Ohler! Great to hear the news, hope itef version coming soon. And, can the callback function in Expr.Modify(...) add a "path Expr" parameter to indicate the "normalized path" of the current modifying Node when the ballback func is invoked. I think this will be more useful to me in some case. Or is there already an approach to achieve it?
It will not be possible to add the path to the callback as the path is not carried around with the traversal of the data. It would have to be a completely different function that sacrifices performance for building the path.
It will not be possible to add the path to the callback as the path is not carried around with the traversal of the data. It would have to be a completely different function that sacrifices performance for building the path.
Oh I see, thank you so much and your Great oj&jp !!!
What could be done is to add a jp.PathsTo(expr jp.Expr)
function or something like that that would return a slice of paths that match the expr. It will be significantly slow but would be able to return paths to all the matches.
Something else you can try for now is to prepend a jp.Bracket to the path and it will or should print in the IETF bracketed format.
What could be done is to add a
jp.PathsTo(expr jp.Expr)
function or something like that that would return a slice of paths that match the expr. It will be significantly slow but would be able to return paths to all the matches.
yes, that would be very slow. If offer the Path in callback in Modify(...) I think would be enough, since I want to aware which Node (normalized path is unique ID here) I actually modifying when matching multiple Nodes by one Expr.
Something else you can try for now is to prepend a jp.Bracket to the path and it will or should print in the IETF bracketed format.
That is the one I want for now, Thank you for you reply!!!~~~~
I created issue #153 for a jp.PathsTo() function. It will not be possible to change jp.Modify().
I've started a branch named jp-locate. It adds a Expr.BracketString() function and the start of Expr.Locate(). You are welcome to experiment with it but realize it is a work in progress.
I've started a branch named jp-locate. It adds a Expr.BracketString() function and the start of Expr.Locate(). You are welcome to experiment with it but realize it is a work in progress.
ohler,that is nice~
Great Json tools, really!
As IETF says in https://datatracker.ietf.org/doc/draft-ietf-jsonpath-base/ (2.7. Normalized Paths) Is there Normalized Paths implementation in jp? How to get them in API?
thanks!!