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

jsonpath

package
v1.152.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package jsonpath reads one value out of a decoded JSON document by a path an operator writes: "$" for the document itself, ".name" or "['name']" for an object member, and "[n]" for an array element, as in "$.data.events" or "$.contact['id']" (#1870).

It is the subset of JSONPath that addresses one value, plus "[*]" for every element of an array, which only LookupAll reads. There are no filters or recursive descent: a webhook source uses a path to find its event array, and an event's id, type and key, and each of those is one place in the document. A token every item of an array must carry (Microsoft Graph's value[*].clientState, #2223) is the one place "[*]" is read.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Scalar

func Scalar(v any) string

Scalar renders a looked-up value as the text a column stores: a string as itself, a number as written, true and false as words, null as empty, and an object or array as its compact JSON.

Types

type Path

type Path struct {
	// contains filtered or unexported fields
}

Path is a parsed path.

func Parse

func Parse(text string) (Path, error)

Parse reads a path. The leading "$" may be omitted: "data.id" is "$.data.id".

func (Path) HasWildcard added in v1.152.1

func (p Path) HasWildcard() bool

HasWildcard reports whether the path steps through every element of an array ("[*]"), and so addresses many values rather than one.

func (Path) Lookup

func (p Path) Lookup(doc any) (any, bool)

Lookup returns the value the path addresses in doc, and false when any step is missing or of the wrong kind. A "[*]" step addresses no one value, so a path holding one is never found; LookupAll reads it.

func (Path) LookupAll added in v1.152.1

func (p Path) LookupAll(doc any) ([]any, bool)

LookupAll returns every value the path addresses in doc: one for a path with no "[*]", and one per element of each array a "[*]" steps through. It reports false when any step is missing or of the wrong kind for any element, and for a "[*]" over an empty array, since a value every element must carry is then carried by none.

func (Path) String

func (p Path) String() string

String is the path as it was written.

Jump to

Keyboard shortcuts

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