Documentation
¶
Overview ¶
Package jsonpointer provides JSONPointer an implementation of RFC6901 https://datatracker.ietf.org/doc/html/rfc6901
Index ¶
Constants ¶
const ( // ErrNotFound is returned when the target is not found. ErrNotFound = errors.Error("not found") // ErrInvalidPath is returned when the path is invalid. ErrInvalidPath = errors.Error("invalid path") // ErrValidation is returned when the jsonpointer is invalid. ErrValidation = errors.Error("validation error") // ErrSkipInterface is returned when this implementation of the interface is not applicable to the current type. ErrSkipInterface = errors.Error("skip interface") )
const (
DefaultStructTag = "key"
)
Variables ¶
This section is empty.
Functions ¶
func EscapeString ¶ added in v0.2.2
EscapeString escapes a string for use as a reference token in a JSON pointer according to RFC6901. It replaces "~" with "~0" and "/" with "~1" as required by the specification. This function should be used when constructing JSON pointers from string values that may contain these special characters.
func GetTarget ¶
func GetTarget(source any, pointer JSONPointer, opts ...option) (any, error)
GetTarget will evaluate the JSONPointer against the source and return the target. WithStructTags can be used to set the type of struct tags to use when navigating structs. If the struct implements any of the Navigable interfaces it will be used to navigate the source.
func WithStructTags ¶
func WithStructTags(structTags ...string) option
WithStructTags will set the type of struct tags to use when navigating structs.
Types ¶
type IndexNavigable ¶
type IndexNavigable interface {
}IndexNavigable is an interface that can be implemented by a struct to allow navigation by index if the struct wraps some slice like type.
type JSONPointer ¶
type JSONPointer string
JSONPointer represents a JSON Pointer value as defined by RFC6901 https://datatracker.ietf.org/doc/html/rfc6901
func PartsToJSONPointer ¶
func PartsToJSONPointer(parts []string) JSONPointer
PartsToJSONPointer will convert the exploded parts of a JSONPointer to a JSONPointer.
func (JSONPointer) String ¶ added in v1.0.0
func (j JSONPointer) String() string
func (JSONPointer) Validate ¶
func (j JSONPointer) Validate() error
Validate will validate the JSONPointer is valid as per RFC6901.
type KeyNavigable ¶
type KeyNavigable interface {
}KeyNavigable is an interface that can be implemented by a struct to allow navigation by key, bypassing navigating by struct tags.
type NavigableNoder ¶
type NavigableNoder interface {
}NavigableNoder is an interface that can be implemented by a struct to allow returning an alternative node to evaluate instead of the struct itself.