jsonpath

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package jsonpath implements JSONPath (RFC 9535): parsing a query with Parse and evaluating it against a decoded JSON document with Eval.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unwrap

func Unwrap(nodes []value.Value) (value.Value, bool)

Unwrap applies the count rule used by queries and filters to collapse a node list to a single value: no nodes yields (nil, false); exactly one node yields that node; more than one yields them as a value.List.

Types

type ParseError

type ParseError struct {
	Pos int
	Msg string
}

ParseError reports a query that does not match the JSONPath grammar (RFC 9535). Pos is a rune offset into the query string.

func (*ParseError) Error

func (e *ParseError) Error() string

type Query

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

Query is a parsed JSONPath query, ready to be evaluated with Eval.

func Parse

func Parse(expr string) (*Query, error)

Parse parses a JSONPath query (RFC 9535). The query must start with the root identifier "$" and consume the whole input.

func (*Query) Eval

func (q *Query) Eval(root value.Value) []value.Value

Eval evaluates the query against root, returning the selected nodes in document order: for a descendant segment, a node is visited before its children (pre-order); object members are visited in the order they are stored (DecodeJSON stores them sorted by key, so a query over decoded JSON always sees a deterministic order).

Jump to

Keyboard shortcuts

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