path

package
v0.25.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DottedPathToJSONPointerPath

func DottedPathToJSONPointerPath(path string) (string, error)

DottedPathToJSONPointerPath converts a dotted path to a JSON Pointer path.

It returns an error if the path is invalid.

func GetMapPathValue

func GetMapPathValue(data map[string]any, path string) (any, error)

GetMapPathValue returns the value at the given path in the map.

It performs faster than the generic GetPathValue function. It returns an error if the path is invalid or the value is not found.

func GetPathValue

func GetPathValue[T any](data T, path string) (any, error)

GetPathValue returns the value at the given path in the data.

It returns an error if the path is invalid or the value is not found.

func GetSlicePathValue

func GetSlicePathValue(data []any, path string) (any, error)

GetSlicePathValue returns the value at the given path in the slice.

It performs faster than the generic GetPathValue function. It returns an error if the path is invalid or the value is not found.

func JSONPointerPathToDottedPath

func JSONPointerPathToDottedPath(path string) (string, error)

JSONPointerPathToDottedPath converts a JSON Pointer path to a dotted path.

It returns an error if the path is invalid.

func ParseAnyToDottedPath added in v0.15.0

func ParseAnyToDottedPath(data any, inc func(key, value any) bool) []string

ParseAnyToDottedPath parses any to dotted path. includes any key-value/index-element pairs from the data for which the inc function returns true. if inc is nil, default to always include.

It returns a list of paths found in the given data, sorted by "path length" and lexical order.

func ParseDottedPath

func ParseDottedPath(path string) ([]string, error)

ParseDottedPath parses a dotted path into its segments.

It returns an error if the path is invalid.

func ParseJSONPointer

func ParseJSONPointer(path string) ([]string, error)

ParseJSONPointer parses a JSON Pointer path into its segments. The JSON Pointer path is a string that represents a path to a value in a JSON document. The JSON Pointer path follows the specification defined in RFC 6901.

It returns an error if the path is invalid.

func PartsToDottedPath

func PartsToDottedPath(parts []string) string

PartsToDottedPath converts path parts to a dotted path.

It returns an error if the parts constitute an invalid path.

func PartsToJSONPointerPath

func PartsToJSONPointerPath(parts []string) (string, error)

PartsToJSONPointerPath converts path parts to a JSON Pointer path.

It returns an error if the parts constitute an invalid path.

func SetPathValue

func SetPathValue[T any](data T, path string, value any) error

SetPathValue sets the given value at the given path in the data.

Currently only supports []any and map[string]any data types. If data is nil, the value cannot be set, but no error is returned. It returns an error if the path is invalid or the value cannot be set.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL