json

package
v0.0.0-...-ab277fa Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = map[string]charlang.Object{

	"Marshal": &charlang.Function{
		Name:    "Marshal",
		Value:   stdlib.FuncPORO(marshalFunc),
		ValueEx: stdlib.FuncPOROEx(marshalFunc),
	},

	"MarshalIndent": &charlang.Function{
		Name:    "MarshalIndent",
		Value:   stdlib.FuncPOssRO(marshalIndentFunc),
		ValueEx: stdlib.FuncPOssROEx(marshalIndentFunc),
	},

	"Indent": &charlang.Function{
		Name:    "Indent",
		Value:   stdlib.FuncPb2ssRO(indentFunc),
		ValueEx: stdlib.FuncPb2ssROEx(indentFunc),
	},

	"RawMessage": &charlang.Function{
		Name:    "RawMessage",
		Value:   stdlib.FuncPb2RO(rawMessageFunc),
		ValueEx: stdlib.FuncPb2ROEx(rawMessageFunc),
	},

	"Compact": &charlang.Function{
		Name:    "Compact",
		Value:   stdlib.FuncPb2bRO(compactFunc),
		ValueEx: stdlib.FuncPb2bROEx(compactFunc),
	},

	"Quote": &charlang.Function{
		Name:    "Quote",
		Value:   stdlib.FuncPORO(quoteFunc),
		ValueEx: stdlib.FuncPOROEx(quoteFunc),
	},

	"NoQuote": &charlang.Function{
		Name:    "NoQuote",
		Value:   stdlib.FuncPORO(noQuoteFunc),
		ValueEx: stdlib.FuncPOROEx(noQuoteFunc),
	},

	"NoEscape": &charlang.Function{
		Name:    "NoEscape",
		Value:   stdlib.FuncPORO(noEscapeFunc),
		ValueEx: stdlib.FuncPOROEx(noEscapeFunc),
	},

	"Unmarshal": &charlang.Function{
		Name:    "Unmarshal",
		Value:   stdlib.FuncPb2RO(unmarshalFunc),
		ValueEx: stdlib.FuncPb2ROEx(unmarshalFunc),
	},

	"Valid": &charlang.Function{
		Name:    "Valid",
		Value:   stdlib.FuncPb2RO(validFunc),
		ValueEx: stdlib.FuncPb2ROEx(validFunc),
	},
}

Module represents json module.

Functions

func Marshal

func Marshal(v charlang.Object) ([]byte, error)

Marshal returns the JSON encoding of v.

func MarshalIndent

func MarshalIndent(v charlang.Object, prefix, indent string) ([]byte, error)

MarshalIndent is like Marshal but applies Indent 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) (charlang.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 EncoderOptions

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

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

func (*EncoderOptions) IndexGet

func (eo *EncoderOptions) IndexGet(index charlang.Object) (ret charlang.Object, err error)

IndexGet implements charlang.Object interface.

func (*EncoderOptions) IndexSet

func (eo *EncoderOptions) IndexSet(index, value charlang.Object) error

IndexSet implements charlang.Object interface.

func (*EncoderOptions) String

func (eo *EncoderOptions) String() string

String implements charlang.Object interface.

func (*EncoderOptions) TypeName

func (eo *EncoderOptions) TypeName() string

TypeName implements charlang.Object interface.

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 charlang.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 {
	charlang.ObjectImpl
	Value []byte
}

RawMessage represents raw encoded json message to directly use value of MarshalJSON without encoding.

func (*RawMessage) IndexGet

func (rm *RawMessage) IndexGet(index charlang.Object) (ret charlang.Object, err error)

IndexGet implements charlang.Object interface.

func (*RawMessage) IndexSet

func (rm *RawMessage) IndexSet(index, value charlang.Object) error

IndexSet implements charlang.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) String

func (rm *RawMessage) String() string

String implements charlang.Object interface.

func (*RawMessage) TypeName

func (rm *RawMessage) TypeName() string

TypeName implements charlang.Object interface.

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 charlang.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