package jsonpath is a template engine using jsonpath syntax, which can be seen at In addition, it has {range} {end} function to iterate list and slice.



    This section is empty.


    View Source
    var (
    	ErrSyntax = errors.New("invalid syntax")
    View Source
    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

    func UnquoteExtend(s string) (string, error)

      UnquoteExtend is almost same as strconv.Unquote(), but it support parse single quotes as a string


      type ArrayNode

      type ArrayNode struct {
      	Params [3]ParamsEntry // start, end, step

        ArrayNode holds start, end, step information for array index selection

        func (*ArrayNode) String

        func (a *ArrayNode) String() string

        type BoolNode

        type BoolNode struct {
        	Value bool

          BoolNode holds bool value

          func (*BoolNode) String

          func (b *BoolNode) String() string

          type FieldNode

          type FieldNode struct {
          	Value string

            FieldNode holds field of struct

            func (*FieldNode) String

            func (f *FieldNode) String() string

            type FilterNode

            type FilterNode struct {
            	Left     *ListNode
            	Right    *ListNode
            	Operator string

              FilterNode holds operand and operator information for filter

              func (*FilterNode) String

              func (f *FilterNode) String() string

              type FloatNode

              type FloatNode struct {
              	Value float64

                FloatNode holds float value

                func (*FloatNode) String

                func (i *FloatNode) String() string

                type IdentifierNode

                type IdentifierNode struct {
                	Name string

                  IdentifierNode holds an identifier

                  func (*IdentifierNode) String

                  func (f *IdentifierNode) String() string

                  type IntNode

                  type IntNode struct {
                  	Value int

                    IntNode holds integer value

                    func (*IntNode) String

                    func (i *IntNode) String() string

                    type JSONPath

                    type JSONPath struct {
                    	// contains filtered or unexported fields

                    func New

                    func New(name string) *JSONPath

                      New creates a new JSONPath with the given name.

                      func (*JSONPath) AllowMissingKeys

                      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 (*JSONPath) Execute

                        func (j *JSONPath) Execute(wr io.Writer, data interface{}) error

                          Execute bounds data into template and writes the result.

                          func (*JSONPath) FindResults

                          func (j *JSONPath) FindResults(data interface{}) ([][]Value, error)

                          func (*JSONPath) Parse

                          func (j *JSONPath) Parse(text string) error

                            Parse parses the given template and returns an error.

                            func (*JSONPath) PrintResults

                            func (j *JSONPath) PrintResults(wr io.Writer, results []Value) error

                              PrintResults writes the results into writer

                              type ListNode

                              type ListNode struct {
                              	Nodes []Node // The element nodes in lexical order.

                                ListNode holds a sequence of nodes.

                                func (*ListNode) String

                                func (l *ListNode) String() string

                                type Node

                                type Node interface {
                                	Type() NodeType
                                	String() string

                                type NodeType

                                type NodeType int

                                  NodeType identifies the type of a parse tree node.

                                  const (
                                  	NodeText NodeType = iota

                                  func (NodeType) String

                                  func (t NodeType) String() string

                                  func (NodeType) Type

                                  func (t NodeType) Type() NodeType

                                    Type returns itself and provides an easy default implementation

                                    type ParamsEntry

                                    type ParamsEntry struct {
                                    	Value   int
                                    	Known   bool // whether the value is known when parse it
                                    	Derived bool

                                      ParamsEntry holds param information for ArrayNode

                                      type Parser

                                      type Parser struct {
                                      	Name string
                                      	Root *ListNode
                                      	// contains filtered or unexported fields

                                      func NewParser

                                      func NewParser(name string) *Parser

                                      func Parse

                                      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 (*Parser) Parse

                                        func (p *Parser) Parse(text string) error

                                        type RecursiveNode

                                        type RecursiveNode struct {

                                          RecursiveNode means a recursive descent operator

                                          func (*RecursiveNode) String

                                          func (r *RecursiveNode) String() string

                                          type TextNode

                                          type TextNode struct {
                                          	Text string // The text; may span newlines.

                                            TextNode holds plain text.

                                            func (*TextNode) String

                                            func (t *TextNode) String() string

                                            type UnionNode

                                            type UnionNode struct {
                                            	Nodes []*ListNode

                                              UnionNode is union of ListNode

                                              func (*UnionNode) String

                                              func (u *UnionNode) String() string

                                              type Value

                                              type Value struct {
                                              	// contains filtered or unexported fields

                                                A wrapper around reflect.Value that allows callers to call Set() on a Value retrieved from inside a map index.

                                                In the normal reflect package, the value in a map index is not addressable, because the internal map implementation might have to rearrange the map storage.

                                                In this implementation, we keep an extra reference to the map that "owns" the value, so that we can call Set() on it.

                                                func ValueOf

                                                func ValueOf(v interface{}) Value

                                                func Wrap

                                                func Wrap(v reflect.Value) Value

                                                func (Value) CanSet

                                                func (v Value) CanSet() bool

                                                func (*Value) Set

                                                func (v *Value) Set(newV reflect.Value)

                                                type WildcardNode

                                                type WildcardNode struct {

                                                  WildcardNode means a wildcard

                                                  func (*WildcardNode) String

                                                  func (i *WildcardNode) String() string