Documentation ¶
Overview ¶
Package mongoextjson allows to encode/decode MongoDB extended JSON
Index ¶
- func Compact(dst *bytes.Buffer, src []byte) error
- func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error
- func Marshal(value interface{}) ([]byte, error)
- func MarshalCanonical(value interface{}) ([]byte, error)
- func Unmarshal(data []byte, value interface{}) error
- type Decoder
- type Delim
- type Encoder
- type Extension
- func (e *Extension) DecodeConst(name string, value interface{})
- func (e *Extension) DecodeFunc(name string, key string, args ...string)
- func (e *Extension) DecodeKeyed(key string, decode func(data []byte) (interface{}, error))
- func (e *Extension) DecodeTrailingCommas(accept bool)
- func (e *Extension) DecodeUnquotedKeys(accept bool)
- func (e *Extension) EncodeType(sample interface{}, encode func(v interface{}) ([]byte, error))
- func (e *Extension) Extend(ext *Extension)
- type InvalidUTF8Error
- type InvalidUnmarshalError
- type Marshaler
- type MarshalerError
- type Number
- type SyntaxError
- type Token
- type UnmarshalFieldError
- type UnmarshalTypeError
- type Unmarshaler
- type UnsupportedTypeError
- type UnsupportedValueError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compact ¶
Compact appends to dst the JSON-encoded src with insignificant space characters elided.
func Indent ¶
Indent appends to dst an indented form of the JSON-encoded src. Each element in a JSON object or array begins on a new, indented line beginning with prefix followed by one or more copies of indent according to the indentation nesting. The data appended to dst does not begin with the prefix nor any indentation, to make it easier to embed inside other formatted JSON data. Although leading space characters (space, tab, carriage return, newline) at the beginning of src are dropped, trailing space characters at the end of src are preserved and copied to dst. For example, if src has no trailing spaces, neither will dst; if src ends in a trailing newline, so will dst.
func Marshal ¶
Marshal return the BSON extended JSON encoding of value. The output is not a valid JSON and will look like
{ "_id": ObjectId("5a934e000102030405000000")}
func MarshalCanonical ¶
MarshalCanonical return the BSON extended JSON encoding of value. The output is a valid JSON and will look like
{ "_id": {"$oid": "5a934e000102030405000000"}}
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder reads and decodes JSON values from an input stream.
func NewDecoder ¶
NewDecoder returns a new decoder that reads from r.
The decoder introduces its own buffering and may read data from r beyond the JSON values requested.
func (*Decoder) Buffered ¶
Buffered returns a reader of the data remaining in the Decoder's buffer. The reader is valid until the next call to Decode.
func (*Decoder) Decode ¶
Decode reads the next JSON-encoded value from its input and stores it in the value pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON into a Go value.
func (*Decoder) More ¶
More reports whether there is another element in the current array or object being parsed.
func (*Decoder) Token ¶
Token returns the next JSON token in the input stream. At the end of the input stream, Token returns nil, io.EOF.
Token guarantees that the delimiters [ ] { } it returns are properly nested and matched: if Token encounters an unexpected delimiter in the input, it will return an error.
The input stream consists of basic JSON values—bool, string, number, and null—along with delimiters [ ] { } of type Delim to mark the start and end of arrays and objects. Commas and colons are elided.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder writes JSON values to an output stream.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
func (*Encoder) DisableHTMLEscaping ¶
func (enc *Encoder) DisableHTMLEscaping()
DisableHTMLEscaping causes the encoder not to escape angle brackets ("<" and ">") or ampersands ("&") in JSON strings.
func (*Encoder) Encode ¶
Encode writes the JSON encoding of v to the stream, followed by a newline character.
See the documentation for Marshal for details about the conversion of Go values to JSON.
type Extension ¶
type Extension struct {
// contains filtered or unexported fields
}
Extension holds a set of additional rules to be used when unmarshaling strict JSON or JSON-like content.
func (*Extension) DecodeConst ¶
DecodeConst defines a constant name that may be observed inside JSON content and will be decoded with the provided value.
func (*Extension) DecodeFunc ¶
DecodeFunc defines a function call that may be observed inside JSON content. A function with the provided name will be unmarshaled as the document {key: {args[0]: ..., args[N]: ...}}.
func (*Extension) DecodeKeyed ¶
DecodeKeyed defines a key that when observed as the first element inside a JSON document triggers the decoding of that document via the provided decode function.
func (*Extension) DecodeTrailingCommas ¶
DecodeTrailingCommas defines whether to accept trailing commas in maps and arrays.
func (*Extension) DecodeUnquotedKeys ¶
DecodeUnquotedKeys defines whether to accept map keys that are unquoted strings.
func (*Extension) EncodeType ¶
EncodeType registers a function to encode values with the same type of the provided sample.
type InvalidUTF8Error ¶
type InvalidUTF8Error struct {
S string // the whole string value that caused the error
}
InvalidUTF8Error before Go 1.2, an InvalidUTF8Error was returned by Marshal when attempting to encode a string value with invalid UTF-8 sequences. As of Go 1.2, Marshal instead coerces the string to valid UTF-8 by replacing invalid bytes with the Unicode replacement rune U+FFFD. This error is no longer generated but is kept for backwards compatibility with programs that might mention it.
func (*InvalidUTF8Error) Error ¶
func (e *InvalidUTF8Error) Error() string
type InvalidUnmarshalError ¶
An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)
func (*InvalidUnmarshalError) Error ¶
func (e *InvalidUnmarshalError) Error() string
type Marshaler ¶
Marshaler is the interface implemented by types that can marshal themselves into valid JSON.
type MarshalerError ¶
A MarshalerError is returned by Marshal when attempting to marshal an invalid JSON
func (*MarshalerError) Error ¶
func (e *MarshalerError) Error() string
type Number ¶
type Number string
A Number represents a JSON number literal.
type SyntaxError ¶
type SyntaxError struct { Offset int64 // error occurred after reading Offset bytes // contains filtered or unexported fields }
A SyntaxError is a description of a JSON syntax error.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
type Token ¶
type Token interface{}
A Token holds a value of one of these types:
Delim, for the four JSON delimiters [ ] { } bool, for JSON booleans float64, for JSON numbers Number, for JSON numbers string, for JSON string literals nil, for JSON null
type UnmarshalFieldError ¶
type UnmarshalFieldError struct { Key string Type reflect.Type Field reflect.StructField }
An UnmarshalFieldError describes a JSON object key that led to an unexported (and therefore unwritable) struct field. (No longer used; kept for compatibility.)
func (*UnmarshalFieldError) Error ¶
func (e *UnmarshalFieldError) Error() string
type UnmarshalTypeError ¶
type UnmarshalTypeError struct { Value string // description of JSON value - "bool", "array", "number -5" Type reflect.Type // type of Go value it could not be assigned to Offset int64 // error occurred after reading Offset bytes }
An UnmarshalTypeError describes a JSON value that was not appropriate for a value of a specific Go type.
func (*UnmarshalTypeError) Error ¶
func (e *UnmarshalTypeError) Error() string
type Unmarshaler ¶
Unmarshaler is the interface implemented by types that can unmarshal a JSON description of themselves. The input can be assumed to be a valid encoding of a JSON value. UnmarshalJSON must copy the JSON data if it wishes to retain the data after returning.
type UnsupportedTypeError ¶
An UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.
func (*UnsupportedTypeError) Error ¶
func (e *UnsupportedTypeError) Error() string
type UnsupportedValueError ¶
An UnsupportedValueError is returned by Marshal when attempting to encode an unsupported value.
func (*UnsupportedValueError) Error ¶
func (e *UnsupportedValueError) Error() string