Documentation
¶
Index ¶
- func Canonical(raw string) string
- func DeleteJSON(existing []byte, path string) ([]byte, error)
- func EnsureArrayElem(existing []byte, path, elem string) ([]byte, error)
- func EscapePath(segment string) string
- func GetJSON(existing []byte, path string) (string, bool)
- func ObjectRoot(doc []byte) error
- func RemoveArrayElem(existing []byte, path, elem string) ([]byte, error)
- func SetJSON(existing []byte, path string, value any) ([]byte, error)
- func Standardize(jsonc []byte) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Canonical ¶
Canonical returns a key-order-independent, whitespace-normalized form of a JSON value (encoding/json marshals map keys sorted). Non-JSON input is returned unchanged, so unresolved ${...} tokens pass through untouched.
func DeleteJSON ¶
DeleteJSON removes the value at a dotted path, preserving the rest of the document. A missing path is not an error — the delete is already done.
func EnsureArrayElem ¶
EnsureArrayElem appends string elem to the array at path if absent. An existing non-array value at path is an error: the ".-1" append would turn it into `{"-1": elem}` — silent corruption.
func EscapePath ¶
EscapePath escapes one config-supplied name for use as a single segment of a gjson/sjson dotted path, so the segment addresses a literal key instead of being interpreted as path syntax. gjson and sjson honor the same backslash escaping, so escaped reads and writes address the same key.
func ObjectRoot ¶
ObjectRoot verifies the document's root value is a JSON object. Managed configs are always objects; a keyed write into an array or scalar root would silently corrupt it, so anything else is rejected up front.
func RemoveArrayElem ¶
RemoveArrayElem deletes every occurrence of string elem from the array at path; an absent elem (or array) leaves the document untouched. An existing non-array value is an error, matching EnsureArrayElem — a silent no-op would leave a corrupt value in place unnoticed.
func Standardize ¶
Standardize converts JSONC to plain JSON (dropping comments). Empty -> "{}".
Types ¶
This section is empty.