Documentation
¶
Index ¶
- Constants
- Variables
- func Loads(src string) (int, interface{}, error)
- func LoadsUseNumber(src string) (int, interface{}, error)
- type Iterator
- type ListIterator
- type Node
- func (self *Node) Add(node Node) error
- func (self *Node) AddAny(val interface{}) error
- func (self *Node) Array() ([]interface{}, error)
- func (self *Node) ArrayUseNode() ([]Node, error)
- func (self *Node) ArrayUseNumber() ([]interface{}, error)
- func (self *Node) Bool() (bool, error)
- func (self *Node) Cap() (int, error)
- func (self *Node) Check() error
- func (self Node) Error() string
- func (self *Node) Exists() bool
- func (self *Node) Float64() (float64, error)
- func (self *Node) ForEach(sc Scanner) error
- func (self *Node) Get(key string) *Node
- func (self *Node) GetByPath(path ...interface{}) *Node
- func (self *Node) Index(idx int) *Node
- func (self *Node) IndexOrGet(idx int, key string) *Node
- func (self *Node) IndexPair(idx int) *Pair
- func (self *Node) Int64() (int64, error)
- func (self *Node) Interface() (interface{}, error)
- func (self *Node) InterfaceUseNode() (interface{}, error)
- func (self *Node) InterfaceUseNumber() (interface{}, error)
- func (self Node) IsRaw() bool
- func (self *Node) Len() (int, error)
- func (self *Node) Load() error
- func (self *Node) LoadAll() error
- func (self *Node) Map() (map[string]interface{}, error)
- func (self *Node) MapUseNode() (map[string]Node, error)
- func (self *Node) MapUseNumber() (map[string]interface{}, error)
- func (self *Node) MarshalJSON() ([]byte, error)
- func (self *Node) Number() (json.Number, error)
- func (self *Node) Properties() (ObjectIterator, error)
- func (self *Node) Raw() (string, error)
- func (self *Node) Set(key string, node Node) (bool, error)
- func (self *Node) SetAny(key string, val interface{}) (bool, error)
- func (self *Node) SetAnyByIndex(index int, val interface{}) (bool, error)
- func (self *Node) SetByIndex(index int, node Node) (bool, error)
- func (self *Node) SortKeys(recurse bool) (err error)
- func (self *Node) StrictFloat64() (float64, error)
- func (self *Node) StrictInt64() (int64, error)
- func (self *Node) StrictNumber() (json.Number, error)
- func (self *Node) StrictString() (string, error)
- func (self *Node) String() (string, error)
- func (self Node) Type() int
- func (self *Node) UnmarshalJSON(data []byte) (err error)
- func (self *Node) UnsafeArray() ([]Node, error)
- func (self *Node) UnsafeMap() ([]Pair, error)
- func (self *Node) Unset(key string) (bool, error)
- func (self *Node) UnsetByIndex(index int) (bool, error)
- func (self *Node) Valid() bool
- func (self *Node) Values() (ListIterator, error)
- type ObjectIterator
- type Pair
- type PairSlice
- type Parser
- type Scanner
- type Searcher
- type Sequence
Constants ¶
const ( V_NONE = 0 V_ERROR = 1 V_NULL = 2 V_TRUE = 3 V_FALSE = 4 V_ARRAY = 5 V_OBJECT = 6 V_STRING = 7 V_NUMBER = int(_V_NUMBER) V_ANY = int(_V_ANY) )
Variables ¶
var ( ErrNotExist error = newError(_ERR_NOT_FOUND, "value not exists") ErrUnsupportType error = newError(_ERR_UNSUPPORT_TYPE, "unsupported type") )
Functions ¶
func LoadsUseNumber ¶
LoadsUseNumber parse all json into interface{}, with numeric nodes casted to json.Number
Types ¶
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
type ListIterator ¶
type ListIterator struct {
Iterator
}
ListIterator is specialized iterator for V_ARRAY
func (*ListIterator) Next ¶
func (self *ListIterator) Next(v *Node) bool
Next scans through children of underlying V_ARRAY, copies each child to v, and returns .HasNext().
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func NewAny ¶
func NewAny(any interface{}) Node
NewAny creates a node of type V_ANY if any's type isn't Node or *Node, which stores interface{} and can be only used for `.Interface()`\`.MarshalJSON()`.
func NewBool ¶
NewBool creates a node of type bool:
If v is true, returns V_TRUE node If v is false, returns V_FALSE node
func NewBytes ¶
NewBytes encodes given src with Base64 (RFC 4648), and creates a node of type V_STRING.
func NewNumber ¶
NewNumber creates a json.Number node v must be a decimal string complying with RFC8259
func NewString ¶
NewString creates a node of type V_STRING. v is considered to be a valid UTF-8 string, which means it won't be validated and unescaped. when the node is encoded to json, v will be escaped.
func (*Node) Add ¶
Add appends the given node under self.
If self is V_NONE or V_NULL, it becomes V_ARRAY and sets the node at index 0.
func (*Node) ArrayUseNode ¶
ArrayUseNode copys both parsed and non-parsed chidren nodes, and indexes them by original order
func (*Node) ArrayUseNumber ¶
ArrayUseNumber loads all indexes of an array node, with numeric nodes casted to json.Number
func (*Node) Bool ¶
Bool returns bool value represented by this node
If node type is not types.V_TRUE or types.V_FALSE, V_RAW (must be a bool json value), or V_ANY (must be a bool type) it will return error
func (*Node) Check ¶
Check checks if the node itself is valid, and return:
- ErrNotFound If the node is nil
- Its underlying error If the node is V_ERROR
func (*Node) ForEach ¶
ForEach scans one V_OBJECT node's children from JSON head to tail, and pass the Sequence and Node of corresponding JSON value.
Especailly, if the node is not V_ARRAY or V_OBJECT, the node itself will be returned and Sequence.Index == -1.
func (*Node) GetByPath ¶
GetByPath load given path on demands, which only ensure nodes before this path got parsed
func (*Node) IndexOrGet ¶
IndexOrGet firstly use idx to index a value and check if its key matches If not, then use the key to search value
func (*Node) Int64 ¶
Int64 casts the node to int64 value, including V_NUMBER, V_TRUE, V_FALSE, V_ANY, V_STRING of invalid digits
func (*Node) Interface ¶
Interface loads all children under all pathes from this node, and converts itself as generic type. WARN: all numberic nodes are casted to float64
func (*Node) InterfaceUseNode ¶
InterfaceUseNode clone itself as a new node, or its children as map[string]Node (or []Node)
func (*Node) InterfaceUseNumber ¶
InterfaceUseNumber works same with Interface() except numberic nodes are casted to json.Number
func (*Node) Len ¶
Len returns children count of a array|object|string node For partially loaded node, it also works but only counts the parsed children
func (*Node) Load ¶
Load loads the node's children as parsed. After calling it, only the node itself can be used on concurrency (not include its children)
func (*Node) LoadAll ¶
LoadAll loads all the node's children and children's children as parsed. After calling it, the node can be safely used on concurrency
func (*Node) MapUseNode ¶
MapUseNode scans both parsed and non-parsed chidren nodes, and map them by their keys
func (*Node) MapUseNumber ¶
MapUseNumber loads all keys of an object node, with numeric nodes casted to json.Number
func (*Node) MarshalJSON ¶
func (*Node) Number ¶
Number casts node to float64, including V_NUMBER, V_TRUE, V_FALSE, V_ANY of json.Number, V_STRING of invalid digits
func (*Node) Properties ¶
func (self *Node) Properties() (ObjectIterator, error)
Properties returns iterator for object's children traversal
func (*Node) Set ¶
Set sets the node of given key under self, and reports if the key has existed.
If self is V_NONE or V_NULL, it becomes V_OBJECT and sets the node at the key.
func (*Node) SetAnyByIndex ¶
SetAny wraps val with V_ANY node, and SetByIndex() the node.
func (*Node) SetByIndex ¶
SetByIndex sets the node of given index, and reports if the key has existed.
The index must be within self's children.
func (*Node) SortKeys ¶
SortKeys sorts children of a V_OBJECT node in ascending key-order. If recurse is true, it recursively sorts children's children as long as a V_OBJECT node is found.
func (*Node) StrictFloat64 ¶
Float64 exports underlying float64 value, includeing V_NUMBER, V_ANY
func (*Node) StrictInt64 ¶
StrictInt64 exports underlying int64 value, including V_NUMBER, V_ANY
func (*Node) StrictNumber ¶
Number exports underlying float64 value, including V_NUMBER, V_ANY of json.Number
func (*Node) StrictString ¶
StrictString returns string value (unescaped), includeing V_STRING, V_ANY of string. In other cases, it will return empty string.
func (*Node) String ¶
String returns raw string value if node type is V_STRING. Or return the string representation of other types:
V_NULL => "null", V_TRUE => "true", V_FALSE => "false", V_NUMBER => "[0-9\.]*" V_ANY => interface{}.(string)
func (Node) Type ¶
Type returns json type represented by the node It will be one of belows:
V_NONE = 0 (empty node) V_ERROR = 1 (error node) V_NULL = 2 (json value `null`) V_TRUE = 3 (json value `true`) V_FALSE = 4 (json value `false`) V_ARRAY = 5 (json value array) V_OBJECT = 6 (json value object) V_STRING = 7 (json value string) V_NUMBER = 33 (json value number ) V_ANY = 34 (golang interface{})
func (*Node) UnmarshalJSON ¶
UnmarshalJSON is just an adapter to json.Unmarshaler. If you want better performance, use Searcher.GetByPath() directly
func (*Node) UnsafeArray ¶
ArrayUnsafe exports the underlying pointer to its children array WARN: don't use it unless you know what you are doing
func (*Node) UnsafeMap ¶
MapUnsafe exports the underlying pointer to its children map WARN: don't use it unless you know what you are doing
func (*Node) Unset ¶
Unset remove the node of given key under object parent, and reports if the key has existed.
func (*Node) UnsetByIndex ¶
UnsetByIndex remove the node of given index
func (*Node) Values ¶
func (self *Node) Values() (ListIterator, error)
Values returns iterator for array's children traversal
type ObjectIterator ¶
type ObjectIterator struct {
Iterator
}
ObjectIterator is specialized iterator for V_ARRAY
func (*ObjectIterator) Next ¶
func (self *ObjectIterator) Next(p *Pair) bool
Next scans through children of underlying V_OBJECT, copies each child to v, and returns .HasNext().
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) ExportError ¶
func (self *Parser) ExportError(err types.ParsingError) error
ExportError converts types.ParsingError to std Error
type Searcher ¶
type Searcher struct {
// contains filtered or unexported fields
}