jsonx

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v any, opts ...Option) ([]byte, error)

Marshal marshal value v to json with options

func NewEncoder

func NewEncoder(w io.Writer) *json.Encoder

NewEncoder wraps json.NewEncoder

func Unmarshal

func Unmarshal(data []byte, v any, opts ...Option) error

Unmarshal wraps json.Unmarshal with options

func Write

func Write(w io.Writer, node Node, opts ...Option) error

Write writes a json node to writer w

func WriteFile

func WriteFile(filename string, node Node, perm os.FileMode, opts ...Option) error

WriteFile writer a json node to file

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder wraps json.Decoder with options

func NewDecoder

func NewDecoder(r io.Reader, opts ...Option) *Decoder

NewDecoder creates a decoder with reader and options

func (*Decoder) Decode

func (decoder *Decoder) Decode(v any) error

Decode decodes data and stores it in the valyala pointed to by v

type Node

type Node interface {
	// embed encoding.Node
	encoding.Node
	// Doc returns lead comments
	Doc() *encoding.CommentGroup
	// Comment returns line comments
	Comment() *encoding.CommentGroup
	// NumChild returns number of child nodes
	NumChild() int
	// ByIndex gets ith child node, key is empty if current node is not an object node
	// Panic if i out of range [0,NumChild)
	ByIndex(i int) (key string, node Node)
	// ByKey gets child node by key, nil returned if key not found
	ByKey(key string) Node
	// Value returns value of node as an interface
	Value() any
	// IsEmpty indicates whther node is empty
	IsEmpty() bool
	// contains filtered or unexported methods
}

Node represents top-level json object

func Read

func Read(r io.Reader, opts ...Option) (Node, error)

Read reads a json node from reader r

func ReadBytes

func ReadBytes(data []byte, opts ...Option) (Node, error)

ReadBytes reads a json node from bytes

func ReadFile

func ReadFile(filename string, opts ...Option) (Node, error)

ReadFile reads a json node from file

type Option

type Option func(*options)

Option represents a function for setting options

func WithIndent

func WithIndent(indent string) Option

WithIndent returns an option which with indent while outputing

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix returns an option which with prefix while outputing

func WithSupportComment

func WithSupportComment() Option

WithSupportComment returns an option which sets supportComment true

func WithSupportExtraComma

func WithSupportExtraComma() Option

WithSupportExtraComma returns an option which sets extraComma true

func WithSupportUnquotedKey

func WithSupportUnquotedKey() Option

WithSupportUnquotedKey returns an option which sets unquotedKey true

Jump to

Keyboard shortcuts

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