var ( ErrSyntax = errors.New("invalid syntax") )
var NodeTypeName = map[NodeType]string{ NodeText: "NodeText", NodeArray: "NodeArray", NodeList: "NodeList", NodeField: "NodeField", NodeIdentifier: "NodeIdentifier", NodeFilter: "NodeFilter", NodeInt: "NodeInt", NodeFloat: "NodeFloat", NodeWildcard: "NodeWildcard", NodeRecursive: "NodeRecursive", NodeUnion: "NodeUnion", NodeBool: "NodeBool", }
func UnquoteExtend(s string) (string, error)
UnquoteExtend is almost same as strconv.Unquote(), but it support parse single quotes as a string
ArrayNode holds start, end, step information for array index selection
type ArrayNode struct { NodeType Params [3]ParamsEntry // start, end, step }
func (a *ArrayNode) String() string
BoolNode holds bool value
type BoolNode struct { NodeType Value bool }
func (b *BoolNode) String() string
FieldNode holds field of struct
type FieldNode struct { NodeType Value string }
func (f *FieldNode) String() string
FilterNode holds operand and operator information for filter
type FilterNode struct { NodeType Left *ListNode Right *ListNode Operator string }
func (f *FilterNode) String() string
FloatNode holds float value
type FloatNode struct { NodeType Value float64 }
func (i *FloatNode) String() string
IdentifierNode holds an identifier
type IdentifierNode struct { NodeType Name string }
func (f *IdentifierNode) String() string
IntNode holds integer value
type IntNode struct { NodeType Value int }
func (i *IntNode) String() string
type JSONPath struct {
// contains filtered or unexported fields
}
func New(name string) *JSONPath
New creates a new JSONPath with the given name.
func (j *JSONPath) AllowMissingKeys(allow bool) *JSONPath
AllowMissingKeys allows a caller to specify whether they want an error if a field or map key cannot be located, or simply an empty result. The receiver is returned for chaining.
func (j *JSONPath) EnableJSONOutput(v bool)
EnableJSONOutput changes the PrintResults behavior to return a JSON array of results
func (j *JSONPath) Execute(wr io.Writer, data interface{}) error
Execute bounds data into template and writes the result.
func (j *JSONPath) FindResults(data interface{}) ([][]reflect.Value, error)
func (j *JSONPath) Parse(text string) error
Parse parses the given template and returns an error.
func (j *JSONPath) PrintResults(wr io.Writer, results []reflect.Value) error
PrintResults writes the results into writer
ListNode holds a sequence of nodes.
type ListNode struct { NodeType Nodes []Node // The element nodes in lexical order. }
func (l *ListNode) String() string
type Node interface { Type() NodeType String() string }
NodeType identifies the type of a parse tree node.
type NodeType int
const ( NodeText NodeType = iota NodeArray NodeList NodeField NodeIdentifier NodeFilter NodeInt NodeFloat NodeWildcard NodeRecursive NodeUnion NodeBool )
func (t NodeType) String() string
func (t NodeType) Type() NodeType
Type returns itself and provides an easy default implementation
ParamsEntry holds param information for ArrayNode
type ParamsEntry struct { Value int Known bool // whether the value is known when parse it Derived bool }
type Parser struct { Name string Root *ListNode // contains filtered or unexported fields }
func NewParser(name string) *Parser
func Parse(name, text string) (*Parser, error)
Parse parsed the given text and return a node Parser. If an error is encountered, parsing stops and an empty Parser is returned with the error
func (p *Parser) Parse(text string) error
RecursiveNode means a recursive descent operator
type RecursiveNode struct { NodeType }
func (r *RecursiveNode) String() string
TextNode holds plain text.
type TextNode struct { NodeType Text string // The text; may span newlines. }
func (t *TextNode) String() string
UnionNode is union of ListNode
type UnionNode struct { NodeType Nodes []*ListNode }
func (u *UnionNode) String() string
WildcardNode means a wildcard
type WildcardNode struct { NodeType }
func (i *WildcardNode) String() string