jmespath

package
v1.1.11 Latest Latest
Warning

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

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

README

Embedded go-jmespath

This directory is a source snapshot of github.com/jmespath/go-jmespath v0.4.0 (commit 3d4fd11601ddca248480565884e34e393313cd62). It is kept inside the main module so release binaries and go install ...@version use the same interpreter fixes while the CLI remains compatible with Go 1.17.

Local fixes relative to v0.4.0:

  • object value projections allocate a zero-length, pre-sized slice instead of evaluating synthetic nil elements;
  • array contains() uses the interpreter's recursive equality semantics, as required by JMESPath, instead of Go interface comparability;
  • sort_by() sorts a shallow copy instead of mutating the caller's response slice, so concurrent searches can safely share immutable input;
  • sort_by(), max_by(), and min_by() validate an expression key even for a one-element array, keeping type errors independent of response length;
  • JSON literals are decoded with UseNumber(), and numeric == / != / < / > / <= / >= compare exact JSON decimal values instead of float64;
  • max / min / sum / avg / abs / ceil / floor / to_number / sort and *_by over numbers use exact decimal comparison/arithmetic instead of float64. Results keep every digit of a finite decimal expansion; only avg() can produce a repeating decimal, which is rounded to at least roundedSignificantDigits significant digits. Arithmetic that would have to expand an exponent beyond maxArithmeticExponent into digits fails explicitly, while comparison, sorting, and abs() stay exact for any token.

Keep this package as a frozen upstream snapshot. Apply only relevant upstream correctness or security fixes, and preserve this provenance note and LICENSE.

Documentation

Index

Constants

View Source
const (
	ASTEmpty astNodeType = iota
	ASTComparator
	ASTCurrentNode
	ASTExpRef
	ASTFunctionExpression
	ASTField
	ASTFilterProjection
	ASTFlatten
	ASTIdentity
	ASTIndex
	ASTIndexExpression
	ASTKeyValPair
	ASTLiteral
	ASTMultiSelectHash
	ASTMultiSelectList
	ASTOrExpression
	ASTAndExpression
	ASTNotExpression
	ASTPipe
	ASTProjection
	ASTSubexpression
	ASTSlice
	ASTValueProjection
)

Variables

This section is empty.

Functions

func CanonicalJSONNumber

func CanonicalJSONNumber(raw string) (string, bool)

CanonicalJSONNumber normalizes a JSON number without expanding its decimal exponent. For example, 1, 1.0 and 10e-1 all become "1e0". Only the exponent arithmetic uses big.Int, so a compact token such as 1e1000000000 stays compact in time and memory instead of allocating a billion-digit numerator.

func Search(expression string, data interface{}) (interface{}, error)

Search evaluates a JMESPath expression against input data and returns the result.

Types

type ASTNode

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

ASTNode represents the abstract syntax tree of a JMESPath expression.

func (ASTNode) PrettyPrint

func (node ASTNode) PrettyPrint(indent int) string

PrettyPrint will pretty print the parsed AST. The AST is an implementation detail and this pretty print function is provided as a convenience method to help with debugging. You should not rely on its output as the internal structure of the AST may change at any time.

func (ASTNode) String

func (node ASTNode) String() string

type JMESPath

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

JMESPath is the representation of a compiled JMES path query. A JMESPath is safe for concurrent use by multiple goroutines.

func Compile

func Compile(expression string) (*JMESPath, error)

Compile parses a JMESPath expression and returns, if successful, a JMESPath object that can be used to match against data.

func MustCompile

func MustCompile(expression string) *JMESPath

MustCompile is like Compile but panics if the expression cannot be parsed. It simplifies safe initialization of global variables holding compiled JMESPaths.

func (*JMESPath) Search

func (jp *JMESPath) Search(data interface{}) (interface{}, error)

Search evaluates a JMESPath expression against input data and returns the result.

type Lexer

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

Lexer contains information about the expression being tokenized.

func NewLexer

func NewLexer() *Lexer

NewLexer creates a new JMESPath lexer.

type Parser

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

Parser holds state about the current expression being parsed.

func NewParser

func NewParser() *Parser

NewParser creates a new JMESPath parser.

func (*Parser) Parse

func (p *Parser) Parse(expression string) (ASTNode, error)

Parse will compile a JMESPath expression.

type SyntaxError

type SyntaxError struct {
	Expression string // Expression that generated a SyntaxError
	Offset     int    // The location in the string where the error occurred
	// contains filtered or unexported fields
}

SyntaxError is the main error used whenever a lexing or parsing error occurs.

func (SyntaxError) Error

func (e SyntaxError) Error() string

func (SyntaxError) HighlightLocation

func (e SyntaxError) HighlightLocation() string

HighlightLocation will show where the syntax error occurred. It will place a "^" character on a line below the expression at the point where the syntax error occurred.

Jump to

Keyboard shortcuts

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