Documentation ¶
Index ¶
- Variables
- func Marshal(vm *gad.VM, v gad.Object) ([]byte, error)
- func MarshalIndent(vm *gad.VM, v gad.Object, prefix, indent string) ([]byte, error)
- func Unmarshal(data []byte, opts *DecodeOptions) (gad.Object, error)
- type DecodeOptions
- type EncoderOptions
- type Marshaler
- type MarshalerError
- type RawMessage
- type SyntaxError
- type UnsupportedValueError
Constants ¶
This section is empty.
Variables ¶
var EncoderOptionsType = &gad.BuiltinObjType{
NameValue: "encoderOptions",
}
var Module = map[string]gad.Object{ "Marshal": &gad.Function{ Name: "Marshal", Value: stdlib.FuncPpVM_ORO(marshalFunc), }, "MarshalIndent": &gad.Function{ Name: "MarshalIndent", Value: stdlib.FuncPpVM_OssRO(marshalIndentFunc), }, "IndentCount": &gad.Function{ Name: "IndentCount", Value: stdlib.FuncPb2ssRO(indentFunc), }, "RawMessage": &gad.Function{ Name: "RawMessage", Value: stdlib.FuncPb2RO(rawMessageFunc), }, "Compact": &gad.Function{ Name: "Compact", Value: stdlib.FuncPb2bRO(compactFunc), }, "Quote": &gad.Function{ Name: "Quote", Value: stdlib.FuncPORO(quoteFunc), }, "NoQuote": &gad.Function{ Name: "NoQuote", Value: stdlib.FuncPORO(noQuoteFunc), }, "NoEscape": &gad.Function{ Name: "NoEscape", Value: stdlib.FuncPORO(noEscapeFunc), }, "Unmarshal": &gad.Function{ Name: "Unmarshal", Value: funcPb2b_numberAsDecimal_b_floatAsDecimal_b_intAsDecimal_RO(unmarshalFunc), }, "Valid": &gad.Function{ Name: "Valid", Value: stdlib.FuncPb2RO(validFunc), }, }
Module represents json module.
var RawMessageType = &gad.BuiltinObjType{
NameValue: "rawMessage",
}
Functions ¶
func MarshalIndent ¶
MarshalIndent is like Marshal but applies IndentCount to format the output. Each JSON element in the output will begin on a new line beginning with prefix followed by one or more copies of indent according to the indentation nesting.
Types ¶
type DecodeOptions ¶
type DecodeOptions struct { FloatFunc func(s string) (gad.Object, error) IntFunc func(s string) (gad.Object, error) }
func NewDecodeOptions ¶
func NewDecodeOptions() *DecodeOptions
type EncoderOptions ¶
EncoderOptions represents the encoding options (quote, html escape) to Marshal any Object.
func (*EncoderOptions) ToString ¶
func (eo *EncoderOptions) ToString() string
ToString implements gad.Object interface.
func (*EncoderOptions) Type ¶
func (eo *EncoderOptions) Type() gad.ObjectType
type Marshaler ¶
Marshaler is the interface implemented by types that can marshal themselves into valid JSON.
type MarshalerError ¶
type MarshalerError struct { Object gad.Object Err error // contains filtered or unexported fields }
A MarshalerError represents an error from calling a MarshalJSON or MarshalText method.
func (*MarshalerError) Error ¶
func (e *MarshalerError) Error() string
func (*MarshalerError) Unwrap ¶
func (e *MarshalerError) Unwrap() error
Unwrap returns the underlying error.
type RawMessage ¶
type RawMessage struct { gad.ObjectImpl Value []byte }
RawMessage represents raw encoded json message to directly use value of MarshalJSON without encoding.
func (*RawMessage) MarshalJSON ¶
func (rm *RawMessage) MarshalJSON() ([]byte, error)
MarshalJSON implements Marshaler interface and returns rm as the JSON encoding of rm.Value.
func (*RawMessage) ToString ¶
func (rm *RawMessage) ToString() string
ToString implements gad.Object interface.
func (*RawMessage) Type ¶
func (rm *RawMessage) Type() gad.ObjectType
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 UnsupportedValueError ¶
An UnsupportedValueError is returned by Marshal when attempting to encode an unsupported value.
func (*UnsupportedValueError) Error ¶
func (e *UnsupportedValueError) Error() string