Help us shape the future of Go! Take the 2026 Go Developer Survey

jsonpath

package
v0.37.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package jsonpath parses the path syntax the autoupdate configuration uses to point at a value inside a JSON document, such as "tag_name", "[0].sha" or "versions[0].version".

A path is a non-empty sequence of segments. A field segment is one or more characters other than '.', '[' and ']', and every field except a leading one is preceded by exactly one '.'. An index segment is "[N]", N being one or more ASCII digits; it follows a field, another index or the start of the path, with no '.' before it. Any other path is rejected with an error that wraps ErrInvalidJSONPath and quotes the path.

The package imports only the standard library, so the response parser and the registry validator can share one grammar and reach the same verdict.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidJSONPath = errors.New("invalid JSON path syntax")

ErrInvalidJSONPath is wrapped by every error Parse returns.

Functions

func CutWildcard

func CutWildcard(path string) (rest string, wildcard bool, err error)

CutWildcard splits a versions path at a leading "[*]", the wildcard that applies the rest of the path to every item of an array. It reports whether the wildcard is present and returns the path each item is read with: "" for the item itself, or a path Parse accepts. After "[*]" the rest is either nothing, an index ("[*][0]"), or a '.' followed by a non-empty path. A path without the wildcard is checked by Parse and returned unchanged.

Types

type Kind

type Kind int

Kind tells a field segment from an index segment.

const (
	// KindField selects a member of a JSON object by name.
	KindField Kind = iota
	// KindIndex selects an element of a JSON array by position.
	KindIndex
)

type Segment

type Segment struct {
	Kind  Kind
	Field string // member name, set when Kind is KindField
	Index int    // array position, set when Kind is KindIndex
}

Segment is one step of a parsed path.

func Parse

func Parse(path string) ([]Segment, error)

Parse splits path into its segments, or rejects it when it is outside the grammar described in the package documentation.

Jump to

Keyboard shortcuts

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