Documentation ¶
Index ¶
- Variables
- func Fuzz(data []byte) int
- func Release(root *Root)
- type Node
- func (n *Node) AddElement() *Node
- func (n *Node) AddElementNoAlloc(root *Root) *Node
- func (n *Node) AddField(name string) *Node
- func (n *Node) AddFieldNoAlloc(root *Root, name string) *Node
- func (n *Node) AppendEscapedString(out []byte) []byte
- func (n *Node) AsArray() []*Node
- func (n *Node) AsBool() bool
- func (n *Node) AsBytes() []byte
- func (n *Node) AsEscapedString() string
- func (n *Node) AsFieldValue() *Node
- func (n *Node) AsFields() []*Node
- func (n *Node) AsFloat() float64
- func (n *Node) AsInt() int
- func (n *Node) AsInt64() int64
- func (n *Node) AsString() string
- func (n *Node) AsUint64() uint64
- func (n *Node) Dig(path ...string) *Node
- func (n *Node) DigField(path ...string) *Node
- func (n *Node) DigStrict(path ...string) (*StrictNode, error)
- func (n *Node) Encode(out []byte) []byte
- func (n *Node) EncodeToByte() []byte
- func (n *Node) EncodeToString() string
- func (n *Node) InsertElement(pos int) *Node
- func (n *Node) IsArray() bool
- func (n *Node) IsFalse() bool
- func (n *Node) IsField() bool
- func (n *Node) IsNil() bool
- func (n *Node) IsNull() bool
- func (n *Node) IsNumber() bool
- func (n *Node) IsObject() bool
- func (n *Node) IsString() bool
- func (n *Node) IsTrue() bool
- func (n *Node) MergeWith(node *Node) *Node
- func (n *Node) MutateToArray() *Node
- func (n *Node) MutateToBool(value bool) *Node
- func (n *Node) MutateToBytes(value []byte) *Node
- func (n *Node) MutateToBytesCopy(root *Root, value []byte) *Node
- func (n *Node) MutateToEscapedString(value string) *Node
- func (n *Node) MutateToField(newFieldName string) *Node
- func (n *Node) MutateToFloat(value float64) *Node
- func (n *Node) MutateToInt(value int) *Node
- func (n *Node) MutateToInt64(value int64) *Node
- func (n *Node) MutateToJSON(root *Root, json string) *Node
- func (n *Node) MutateToNode(node *Node) *Node
- func (n *Node) MutateToNull() *Node
- func (n *Node) MutateToObject() *Node
- func (n *Node) MutateToStrict() *StrictNode
- func (n *Node) MutateToString(value string) *Node
- func (n *Node) MutateToUint64(value uint64) *Node
- func (n *Node) Suicide()
- func (n *Node) TypeStr() string
- type Root
- func (r *Root) BuffCap() int
- func (r *Root) Clear()
- func (r *Root) DecodeBytes(jsonBytes []byte) error
- func (r *Root) DecodeBytesAdditional(jsonBytes []byte) (*Node, error)
- func (r *Root) DecodeFile(fileName string) error
- func (r *Root) DecodeString(json string) error
- func (r *Root) DecodeStringAdditional(json string) (*Node, error)
- func (r *Root) PoolSize() int
- func (r *Root) ReleaseBufMem()
- func (r *Root) ReleaseMem()
- func (r *Root) ReleasePoolMem()
- type StrictNode
- func (n *StrictNode) AsArray() ([]*Node, error)
- func (n *StrictNode) AsBool() (bool, error)
- func (n *StrictNode) AsBytes() ([]byte, error)
- func (n *StrictNode) AsEscapedString() (string, error)
- func (n *StrictNode) AsFieldValue() (*Node, error)
- func (n *StrictNode) AsFields() ([]*Node, error)
- func (n *StrictNode) AsFloat() (float64, error)
- func (n *StrictNode) AsInt() (int, error)
- func (n *StrictNode) AsInt64() (int64, error)
- func (n *StrictNode) AsString() (string, error)
- func (n *StrictNode) AsUint64() (uint64, error)
Constants ¶
This section is empty.
Variables ¶
var ( StartNodePoolSize = 128 MapUseThreshold = 16 DisableBeautifulErrors = false // set to "true" for best performance, if you have many decode errors // decode errors ErrEmptyJSON = errors.New("json is empty") ErrUnexpectedJSONEnding = errors.New("unexpected ending of json") ErrUnexpectedEndOfString = errors.New("unexpected end of string") ErrUnexpectedEndOfTrue = errors.New("unexpected end of true") ErrUnexpectedEndOfFalse = errors.New("unexpected end of false") ErrUnexpectedEndOfNull = errors.New("unexpected end of null") ErrUnexpectedEndOfObjectField = errors.New("unexpected end of object field") ErrExpectedObjectField = errors.New("expected object field") ErrExpectedObjectFieldSeparator = errors.New("expected object field separator") ErrExpectedValue = errors.New("expected value") ErrExpectedComma = errors.New("expected comma") // api errors ErrRootIsNil = errors.New("root is nil") ErrNotFound = errors.New("node isn't found") ErrNotObject = errors.New("node isn't an object") ErrNotArray = errors.New("node isn't an array") ErrNotBool = errors.New("node isn't a bool") ErrNotString = errors.New("node isn't a string") ErrNotNumber = errors.New("node isn't a number") ErrNotField = errors.New("node isn't an object field") )
Functions ¶
Types ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node Is a building block of the decoded JSON. There is seven basic nodes:
- Object
- Array
- String
- Number
- True
- False
- Null
And a special one – Field, which represents the field(key) on an objects. It allows to easily change field's name, checkout MutateToField() function.
func (*Node) AddElement ¶ added in v0.0.7
func (*Node) AddElementNoAlloc ¶ added in v0.1.3
func (*Node) AddFieldNoAlloc ¶ added in v0.0.14
func (*Node) AppendEscapedString ¶ added in v0.1.6
func (*Node) AsEscapedString ¶
func (*Node) AsFieldValue ¶
func (*Node) Encode ¶
Encode legendary insane encode function uses already created byte buffer to place json data so mem allocations may occur only if buffer isn't long enough use it for performance
func (*Node) EncodeToByte ¶
EncodeToByte legendary insane encode function slow because it allocates new byte buffer on every call use Encode to reuse already created buffer and gain more performance
func (*Node) EncodeToString ¶
EncodeToString legendary insane encode function slow because it allocates new string on every call use Encode to reuse already created buffer and gain more performance
func (*Node) InsertElement ¶
func (*Node) MutateToArray ¶ added in v0.0.20
func (*Node) MutateToBool ¶
func (*Node) MutateToBytes ¶ added in v0.0.20
MutateToBytes mutate to a string and use byte slice as value. It doesn't copy data, so modifications of a slice will change result JSON.
func (*Node) MutateToBytesCopy ¶ added in v0.0.20
MutateToBytes mutate to a string and use byte slice as value. It copies data, so modification of a slice won't change result JSON.
func (*Node) MutateToEscapedString ¶
func (*Node) MutateToField ¶
MutateToField changes name of objects's field works only with Field nodes received by AsField()/AsFields() example: root, err := insaneJSON.DecodeString(`{"a":"a","b":"b"}`) root.AsField("a").MutateToField("new_name") root.Encode() will be {"new_name":"a","b":"b"}
func (*Node) MutateToFloat ¶
func (*Node) MutateToInt ¶
func (*Node) MutateToInt64 ¶ added in v0.0.20
func (*Node) MutateToNode ¶
MutateToNode it isn't safe function, if you create node cycle, encode() may freeze
func (*Node) MutateToNull ¶
func (*Node) MutateToObject ¶
func (*Node) MutateToStrict ¶ added in v0.0.7
func (n *Node) MutateToStrict() *StrictNode
func (*Node) MutateToString ¶
func (*Node) MutateToUint64 ¶ added in v0.0.20
type Root ¶
type Root struct { *Node // contains filtered or unexported fields }
Root is a top Node of decoded JSON. It holds decoder, current JSON data and pool of Nodes. Node pool is used to reduce memory allocations and GC time. Checkout ReleaseMem()/ReleasePoolMem()/ReleaseBufMem() to clear pools. Root can be reused to decode another JSON using DecodeBytes()/DecodeString(). Also Root can decode additional JSON using DecodeAdditionalBytes()/DecodeAdditionalString().
func DecodeBytes ¶
func DecodeFile ¶ added in v0.1.4
func DecodeString ¶
func (*Root) DecodeBytes ¶
DecodeBytes clears Root and decodes new JSON. Useful for reusing Root to reduce allocations.
func (*Root) DecodeBytesAdditional ¶
DecodeBytesAdditional doesn't clean Root, uses Root node pool to decode JSON
func (*Root) DecodeFile ¶ added in v0.1.4
DecodeFile clears Root and decodes new JSON. Useful for reusing Root to reduce allocations.
func (*Root) DecodeString ¶
DecodeString clears Root and decodes new JSON. Useful for reusing Root to reduce allocations.
func (*Root) DecodeStringAdditional ¶
DecodeStringAdditional doesn't clean Root, uses Root node pool to decode JSON
func (*Root) PoolSize ¶ added in v0.0.7
PoolSize returns how many Node objects is in the pool right now.
func (*Root) ReleaseBufMem ¶
func (r *Root) ReleaseBufMem()
ReleaseBufMem sends internal buffer to GC. Useful to reduce memory usage after decoding big JSON.
func (*Root) ReleaseMem ¶
func (r *Root) ReleaseMem()
ReleaseMem sends node pool and internal buffer to GC. Useful to reduce memory usage after decoding big JSON.
func (*Root) ReleasePoolMem ¶
func (r *Root) ReleasePoolMem()
ReleasePoolMem sends node pool to GC. Useful to reduce memory usage after decoding big JSON.
type StrictNode ¶
type StrictNode struct {
*Node
}
StrictNode implements API with error handling. Transform any Node with MutateToStrict(), Mutate*()/As*() functions will return an error
func (*StrictNode) AsArray ¶
func (n *StrictNode) AsArray() ([]*Node, error)
func (*StrictNode) AsBool ¶
func (n *StrictNode) AsBool() (bool, error)
func (*StrictNode) AsBytes ¶
func (n *StrictNode) AsBytes() ([]byte, error)
func (*StrictNode) AsEscapedString ¶
func (n *StrictNode) AsEscapedString() (string, error)
func (*StrictNode) AsFieldValue ¶
func (n *StrictNode) AsFieldValue() (*Node, error)
func (*StrictNode) AsFields ¶
func (n *StrictNode) AsFields() ([]*Node, error)
func (*StrictNode) AsFloat ¶
func (n *StrictNode) AsFloat() (float64, error)
func (*StrictNode) AsInt ¶
func (n *StrictNode) AsInt() (int, error)
func (*StrictNode) AsInt64 ¶ added in v0.0.20
func (n *StrictNode) AsInt64() (int64, error)
func (*StrictNode) AsString ¶
func (n *StrictNode) AsString() (string, error)
func (*StrictNode) AsUint64 ¶ added in v0.0.20
func (n *StrictNode) AsUint64() (uint64, error)