Documentation ¶
Overview ¶
Package qjson most of code here is copyed from std lib
Index ¶
- func JSONIndentMarshalWithPanic(t interface{}) []byte
- func JSONMarshalWithPanic(t interface{}) []byte
- func PrettyMarshal(v interface{}) []byte
- func PrettyMarshalWithIndent(v interface{}) []byte
- type Color
- type DiffItem
- type DiffItems
- type DiffType
- type Formatter
- type JSONTree
- func (tree *JSONTree) ColorfulMarshal() []byte
- func (tree *JSONTree) ColorfulMarshalWithIndent() []byte
- func (tree *JSONTree) Equal(t2 *JSONTree) bool
- func (tree *JSONTree) Find(path string) *Node
- func (tree *JSONTree) IsNull() bool
- func (tree *JSONTree) JSONIndentString() string
- func (tree *JSONTree) JSONString() string
- func (tree *JSONTree) MarshalJSON() ([]byte, error)
- func (tree *JSONTree) Release()
- func (tree *JSONTree) Remove(path string)
- func (tree *JSONTree) UnmarshalJSON(data []byte) (err error)
- type Node
- func (n *Node) AddArrayElem(elem *Node) *Node
- func (n *Node) AddObjectElem(elem *ObjectElem) *Node
- func (n *Node) AsBool() bool
- func (n *Node) AsFloat() float64
- func (n *Node) AsInt() int64
- func (n *Node) AsJSON() string
- func (n *Node) AsMap() map[string]*Node
- func (n *Node) AsString() string
- func (n *Node) AsTree() *JSONTree
- func (n *Node) AsUint() uint64
- func (n *Node) Equal(o *Node) bool
- func (n *Node) Find(key string) *Node
- func (n *Node) GetObjectElemByKey(key string) *ObjectElem
- func (n *Node) Hash() uint64
- func (n *Node) IsBool() bool
- func (n *Node) IsFloat() bool
- func (n *Node) IsInteger() bool
- func (n *Node) IsNull() bool
- func (n *Node) IsNumber() bool
- func (n *Node) IsString() bool
- func (n *Node) MarshalJSON() ([]byte, error)
- func (n *Node) Rehash() uint64
- func (n *Node) RemoveArrayElemByIndex(idx int) bool
- func (n *Node) RemoveObjectElemByKey(key string) bool
- func (n *Node) SetBool(b bool) *Node
- func (n *Node) SetFloat(f float64, prec int) *Node
- func (n *Node) SetInt(num int64) *Node
- func (n *Node) SetObjectBoolElem(key string, value bool) *Node
- func (n *Node) SetObjectIntElem(key string, value int64) *Node
- func (n *Node) SetObjectNodeElem(key string, value *Node) *Node
- func (n *Node) SetObjectStringElem(key, value string) *Node
- func (n *Node) SetObjectUintElem(key string, value uint64) *Node
- func (n *Node) SetRawValue(str string) *Node
- func (n *Node) SetString(str string) *Node
- func (n *Node) SetUint(num uint64) *Node
- type NodeType
- type ObjectElem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSONIndentMarshalWithPanic ¶
func JSONIndentMarshalWithPanic(t interface{}) []byte
JSONIndentMarshalWithPanic json marshal with panic
func JSONMarshalWithPanic ¶
func JSONMarshalWithPanic(t interface{}) []byte
JSONMarshalWithPanic json marshal with panic
func PrettyMarshalWithIndent ¶
func PrettyMarshalWithIndent(v interface{}) []byte
PrettyMarshalWithIndent marshal json with indent
Types ¶
type Formatter ¶
type Formatter struct {
Indent int
}
Formatter json with indent
func NewFormatter ¶
func NewFormatter() *Formatter
NewFormatter returns a new formatter with following default values.
type JSONTree ¶
type JSONTree struct {
Root *Node
}
JSONTree represent full json
func ConvertToJSONTree ¶
ConvertToJSONTree any object to json tree
func (*JSONTree) ColorfulMarshal ¶
ColorfulMarshal print json with color
func (*JSONTree) ColorfulMarshalWithIndent ¶
ColorfulMarshalWithIndent print json with indent
func (*JSONTree) JSONIndentString ¶
JSONIndentString tree to string with indent
func (*JSONTree) MarshalJSON ¶
MarshalJSON json marshaller
func (*JSONTree) UnmarshalJSON ¶
UnmarshalJSON json unmarshaller
type Node ¶
type Node struct { Type NodeType Value string ObjectValues []*ObjectElem ArrayValues []*Node // contains filtered or unexported fields }
Node represent json node
func CreateStringNodeWithValue ¶
CreateStringNodeWithValue create string node
func (*Node) AddObjectElem ¶
func (n *Node) AddObjectElem(elem *ObjectElem) *Node
AddObjectElem to node
func (*Node) GetObjectElemByKey ¶
func (n *Node) GetObjectElemByKey(key string) *ObjectElem
GetObjectElemByKey get object value by key
func (*Node) MarshalJSON ¶
MarshalJSON node is json marshaller too
func (*Node) RemoveArrayElemByIndex ¶
RemoveArrayElemByIndex remove array element
func (*Node) RemoveObjectElemByKey ¶
RemoveObjectElemByKey remove object element
func (*Node) SetObjectBoolElem ¶
SetObjectBoolElem set kv pair
func (*Node) SetObjectIntElem ¶
SetObjectIntElem set kv pair
func (*Node) SetObjectNodeElem ¶
SetObjectNodeElem set kv pair
func (*Node) SetObjectStringElem ¶
SetObjectStringElem set kv pair
func (*Node) SetObjectUintElem ¶
SetObjectUintElem set kv pair
func (*Node) SetRawValue ¶
SetRawValue set raw json string to node
type NodeType ¶
type NodeType byte
NodeType describe a json node type
const ( // Null json node means null Null NodeType = iota // String json node means "any text" String // Bool json node means true/false Bool // Integer json node means integer Integer // Float json node means float number Float // Object json node means k-v object Object // Array json node means array json nodes Array )
type ObjectElem ¶
ObjectElem represent an object
func (*ObjectElem) MarshalJSON ¶
func (e *ObjectElem) MarshalJSON() ([]byte, error)
MarshalJSON object node is json marshaller