YAMLPath
Reading a value by path
The syntax
$ | the root |
. | a child |
.. | recursive descent |
[n] | element n of a sequence |
[*] | every element of a sequence |
A key containing . or * goes in single quotes: $.foo.'bar.baz-*'.hoge. A
single quote inside that is escaped with a backslash.
expressions.PathBuilder builds the same paths in code — Root, Child,
Index, IndexAll, Recursive, then Build — which is what you want when a
segment comes from a variable rather than a literal.
Annotating the source
AnnotateSource returns the lines around the node, with a caret under it:
The boolean is colored. Use it to report on a value your own code rejected
after a successful decode — see Errors.
Working on nodes rather than values
Read and Filter go through the decoder and hand you a Go value. ReadNode
and FilterNode stop at the tree, which is what you want when the
document is the thing you are changing.
Errors
Match a path’s errors with errors.Is against four sentinels: ErrInvalidPath,
ErrInvalidPathString, ErrInvalidQuery and ErrNotFoundNode. A path that
matches nothing returns ErrNotFoundNode, not an empty result.
The same path strings key a CommentMap — see Comments.