json

package
v0.0.0-...-aea1278 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EncoderOptionsType = &gad.BuiltinObjType{
	NameValue: "encoderOptions",
}
View Source
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.

View Source
var RawMessageType = &gad.BuiltinObjType{
	NameValue: "rawMessage",
}

Functions

func Marshal

func Marshal(vm *gad.VM, v gad.Object) ([]byte, error)

Marshal returns the JSON encoding of v.

func MarshalIndent

func MarshalIndent(vm *gad.VM, v gad.Object, prefix, indent string) ([]byte, error)

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.

func Unmarshal

func Unmarshal(data []byte, opts *DecodeOptions) (gad.Object, error)

Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an InvalidUnmarshalError.

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

type EncoderOptions struct {
	gad.ObjectImpl
	Value      gad.Object
	Quote      bool
	EscapeHTML bool
}

EncoderOptions represents the encoding options (quote, html escape) to Marshal any Object.

func (*EncoderOptions) IndexGet

func (eo *EncoderOptions) IndexGet(_ *gad.VM, index gad.Object) (ret gad.Object, err error)

IndexGet implements gad.Object interface.

func (*EncoderOptions) IndexSet

func (eo *EncoderOptions) IndexSet(_ *gad.VM, index, value gad.Object) error

IndexSet implements gad.Object interface.

func (*EncoderOptions) ToString

func (eo *EncoderOptions) ToString() string

ToString implements gad.Object interface.

func (*EncoderOptions) Type

func (eo *EncoderOptions) Type() gad.ObjectType

type Marshaler

type Marshaler interface {
	MarshalJSON() ([]byte, error)
}

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) IndexGet

func (rm *RawMessage) IndexGet(_ *gad.VM, index gad.Object) (ret gad.Object, err error)

IndexGet implements gad.Object interface.

func (*RawMessage) IndexSet

func (rm *RawMessage) IndexSet(_ *gad.VM, index, value gad.Object) error

IndexSet implements gad.Object interface.

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

type UnsupportedValueError struct {
	Object gad.Object
	Str    string
}

An UnsupportedValueError is returned by Marshal when attempting to encode an unsupported value.

func (*UnsupportedValueError) Error

func (e *UnsupportedValueError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL