Documentation
¶
Index ¶
- type Annotation
- type AnnotationKey
- type Kind
- type Node
- func (n *Node) Annotate(a Annotation)
- func (n *Node) CountNodes() int
- func (n *Node) GetAnnotation(lens, name string) (any, bool)
- func (n *Node) GetAnnotations(lens string) []Annotation
- func (n *Node) MarshalJSON() ([]byte, error)
- func (n *Node) Path() string
- func (n *Node) ToAny() any
- func (n *Node) Walk(fn func(*Node) bool)
- func (n *Node) WalkPost(fn func(*Node))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Annotation ¶
type Annotation struct {
Key AnnotationKey
Value any
}
Annotation is a single piece of derived data attached to a node by a lens.
type AnnotationKey ¶
type AnnotationKey struct {
Lens string // e.g. "stats", "merkle", "decode"
Name string // e.g. "mean", "hash", "type"
}
AnnotationKey namespaces annotations to prevent collisions between lenses.
type Node ¶
type Node struct {
Kind Kind
Key string // object key if this is an object value; "" otherwise
Index int // array index if this is an array element; -1 otherwise
Raw string // raw JSON token for leaf nodes (e.g. `"hello"`, `42`, `true`, `null`)
Children []*Node
Parent *Node
// contains filtered or unexported fields
}
Node is the core data structure. Parse once, annotate many times. All lenses read from the same tree and write their own annotation keys.
func (*Node) Annotate ¶
func (n *Node) Annotate(a Annotation)
Annotate stamps an annotation onto this node. Safe for concurrent use.
func (*Node) CountNodes ¶
CountNodes returns the total number of nodes in this subtree (including self).
func (*Node) GetAnnotation ¶
GetAnnotation returns the value for a specific lens+name key.
func (*Node) GetAnnotations ¶
func (n *Node) GetAnnotations(lens string) []Annotation
GetAnnotations returns all annotations for a given lens.
func (*Node) MarshalJSON ¶
MarshalJSON produces compact JSON for this node, preserving key order.
func (*Node) Path ¶
Path returns the dot-notation path from root to this node (e.g. ".users[0].name").