jsonpointer

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package jsonpointer provides JSONPointer an implementation of RFC6901 https://datatracker.ietf.org/doc/html/rfc6901

Index

Constants

View Source
const (
	ErrNotFound    = errors.Error("not found")
	ErrInvalidPath = errors.Error("invalid path")
	ErrValidation  = errors.Error("validation error")
)
View Source
const (
	DefaultStructTag = "key"
)

Variables

This section is empty.

Functions

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 {
	NavigateWithIndex(index int) (any, error)
}

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) Validate

func (j JSONPointer) Validate() error

Validate will validate the JSONPointer is valid as per RFC6901.

type KeyNavigable

type KeyNavigable interface {
	NavigateWithKey(key string) (any, error)
}

KeyNavigable is an interface that can be implemented by a struct to allow navigation by key, bypassing navigating by struct tags.

type NavigableNoder interface {
	GetNavigableNode() any
}

NavigableNoder is an interface that can be implemented by a struct to allow returning an alternative node to evaluate instead of the struct itself.

Jump to

Keyboard shortcuts

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