Documentation ¶
Index ¶
- func PrintJSON(w io.Writer, a Appender) (n int, err error)
- type Appender
- type Document
- func (d *Document) AppendJSON(dst []byte) ([]byte, error)
- func (d *Document) Array() Node
- func (d *Document) Close()
- func (d *Document) False() Node
- func (d *Document) Node(id uint) Node
- func (d *Document) Null() Node
- func (d *Document) Number(f float64) Node
- func (d *Document) Object() Node
- func (d *Document) Parse(s string) (Node, string, error)
- func (d *Document) ParseUnsafe(b []byte) (Node, []byte, error)
- func (d *Document) Reset()
- func (d *Document) Root() Node
- func (d *Document) Text(s string) Node
- func (d *Document) TextHTML(s string) Node
- func (d *Document) TextRaw(s string) Node
- func (d *Document) True() Node
- type IterV
- type Node
- func (n Node) Append(values ...Node)
- func (n Node) AppendJSON(dst []byte) ([]byte, error)
- func (n Node) Bytes() []byte
- func (n Node) Del(key string)
- func (n Node) Document() *Document
- func (n Node) Get(key string) Node
- func (n Node) ID() uint
- func (n Node) Index(i int) Node
- func (n Node) Lookup(path ...string) Node
- func (n Node) PrintJSON(w io.Writer) (int, error)
- func (n Node) Raw() string
- func (n Node) Remove(i int)
- func (n Node) Replace(i int, value Node)
- func (n Node) Set(key string, value Node)
- func (n Node) SetFalse()
- func (n Node) SetFloat(f float64)
- func (n Node) SetInt(i int64)
- func (n Node) SetNull()
- func (n Node) SetString(s string)
- func (n Node) SetStringHTML(s string)
- func (n Node) SetStringRaw(s string)
- func (n Node) SetTrue()
- func (n Node) SetUint(u uint64)
- func (n Node) Slice(i, j int)
- func (n Node) Strip(key string)
- func (n Node) ToBool() (bool, bool)
- func (n Node) ToFloat() (float64, bool)
- func (n Node) ToInt() (int64, bool)
- func (n Node) ToInterface() (interface{}, bool)
- func (n Node) ToUint() (uint64, bool)
- func (n Node) Type() Type
- func (n Node) TypeError(want Type) error
- func (n Node) Unescaped() string
- func (n Node) Values() IterV
- func (n Node) With(id uint) Node
- func (n Node) WrapUnmarshalJSON(u json.Unmarshaler) (err error)
- func (n Node) WrapUnmarshalText(u encoding.TextUnmarshaler) (err error)
- type Pool
- type Type
- type Unmarshaler
- type V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is a JSON document.
func Blank ¶
func Blank() *Document
Blank returns a blank document from the default pool. Use Document.Close() to reset and return the document to the pool.
func (*Document) AppendJSON ¶
AppendJSON appends the JSON data of the document root node to a byte slice.
func (*Document) Close ¶
func (d *Document) Close()
Close resets and returns the document to the default pool to be reused.
func (*Document) False ¶
False adds a new Boolean node with it's value set to false to the document.
func (*Document) ParseUnsafe ¶
ParseUnsafe parses a JSON buffer without copying it to a string and returns the root node as a Partial. Make sure to call Document.Reset() or Document.Close() to avoid memory leaks.
func (*Document) Text ¶
Text adds a new String node to the document escaping JSON unsafe characters.
func (*Document) TextHTML ¶
TextHTML adds a new String node to the document escaping HTML and JSON unsafe characters.
type IterV ¶
type IterV struct { *V // contains filtered or unexported fields }
IterV is an iterator over a node's values.
func (*IterV) Index ¶
Index returns the current iteration index. Before Next() is called for the first time it returns -1. After the iteration has finished it returns -2.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a reference to a node in a JSON Document. It is a versioned reference to avoid document manipulation after reset.
func (Node) AppendJSON ¶
AppendJSON appends a node's JSON data to a byte slice.
func (Node) Bytes ¶
Bytes returns a Node's JSON string as bytes. The slice is NOT a copy of the string's data and SHOULD not be modified.
func (Node) Del ¶
Del finds a key in an Object node's values and removes it. It does not keep the order of keys.
func (Node) Get ¶
Get gets a Node by key. If the key is not found the returned node's id will be MaxID and the Node will behave as empty.
func (Node) Index ¶
Index gets the Node at offset i of an Array. If the index is out of bounds the returned node's id will be MaxID and the Node will behave as empty.
func (Node) Raw ¶
Raw return the JSON string of a Node's value. Object and Array nodes return an empty string. The returned string is NOT safe to use if ParseUnsafe was used.
func (Node) Set ¶
Set assigns a Node to the key of an Object Node. Since most keys need no escaping it doesn't escape the key. If the key needs escaping use strjson.Escaped.
func (Node) SetStringHTML ¶
SetStringHTML sets a Node's value to a string escaping invalid JSON and unsafe HTML characters.
func (Node) SetStringRaw ¶
SetStringRaw sets a Node's value to a string without escaping. Unless the provided string is guaranteed to not contain any JSON invalid characters, JSON output from this Node will be invalid.
func (Node) ToInterface ¶
ToInterface converts a Node to a generic interface{}.
func (Node) Unescaped ¶
Unescaped unescapes the value of a String Node. The returned string is safe to use even if ParseUnsafe was used.
func (Node) WrapUnmarshalJSON ¶
func (n Node) WrapUnmarshalJSON(u json.Unmarshaler) (err error)
WrapUnmarshalJSON wraps a call to the json.Unmarshaler interface
func (Node) WrapUnmarshalText ¶
func (n Node) WrapUnmarshalText(u encoding.TextUnmarshaler) (err error)
WrapUnmarshalText wraps a call to the encoding.TextUnmarshaler interface
type Pool ¶ added in v0.0.5
type Pool struct {
// contains filtered or unexported fields
}
Pool is a pool of document objects
type Type ¶
type Type uint8
Type is the type of a node.
const ( TypeInvalid Type = iota TypeString Type = 1 << iota TypeObject TypeArray TypeNumber TypeBoolean TypeNull TypeAnyValue = TypeString | TypeNumber | TypeBoolean | TypeObject | TypeArray | TypeNull )
Token types and type masks
type Unmarshaler ¶
Unmarshaler is the interface implemented by types that can unmarshal from a Node.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package unjson uses reflection to marshal/unmarshal JSON from njson.Node input It's NOT a 'drop-in' replacement for "encoding/json".
|
Package unjson uses reflection to marshal/unmarshal JSON from njson.Node input It's NOT a 'drop-in' replacement for "encoding/json". |