Documentation ¶
Overview ¶
Package mongoextjson allows to encode/decode MongoDB extended JSON
Index ¶
- func Marshal(value interface{}) ([]byte, error)
- func MarshalCanonical(value interface{}) ([]byte, error)
- func Unmarshal(data []byte, value interface{}) error
- type Decoder
- 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 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 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.
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.
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 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