Documentation
¶
Overview ¶
Package jsontree provides types and utilities for working with parsed JSON value trees — the Go representation produced by json.Unmarshal into any.
A Tree is a type alias for any, constrained by convention to the shapes that encoding/json produces:
- map[string]any (JSON object)
- []any (JSON array)
- string (JSON string)
- float64 (JSON number)
- bool (JSON boolean)
- nil (JSON null)
The tree shape is not JSON-specific — any format that can be parsed into map[string]any / []any (YAML, MessagePack, etc.) is compatible with the utilities in this package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeletePaths ¶
DeletePaths deletes the specified dot-separated paths from the tree in-place. Supports "#" as a wildcard segment for iterating array elements. The caller is responsible for copying the tree first if mutation is not desired.
func WalkPath ¶
WalkPath navigates a map[string]any / []any tree along a dot-separated path and calls visitor(parent, key) at each matching leaf. The visitor receives the parent map and the final key so it can read, write, or delete the entry.
The "#" segment is a wildcard that iterates over []any slices, applying the remaining path to each element.
Missing intermediate keys are silently skipped. If the path leads to a non-existent key, the visitor is not called.
Types ¶
type Tree ¶
type Tree = any
Tree is a Go value tree produced by json.Unmarshal into any. Valid shapes: map[string]any (object), []any (array), string, float64, bool, nil.
This is a type alias (not a defined type), so it is fully interchangeable with any at call sites — no casting or wrapping required.
func DeepCopy ¶
DeepCopy creates a deep copy of a JSON value tree to avoid aliasing. Maps and slices are recursively copied; scalars (string, float64, bool, nil) are returned as-is since they are immutable.
func PickPaths ¶
PickPaths builds a new tree containing only the values at the specified dot-separated paths. The source tree is never mutated. Supports "#" as a wildcard segment for iterating array elements. Returns an empty map (not nil) when no paths match — this is intentional so the result is always a valid tree for downstream operations.