jsonx

package
v0.0.0-...-c39e8e5 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: AGPL-3.0 Imports: 10 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fprint

func Fprint(w io.Writer, v interface{}) error

Fprint formats v in JSONX and prints it into w.

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal formats v in JSONX.

func Print

func Print(v interface{}) error

Print formats v in JSONX and prints it into stdout.

func ReadFile

func ReadFile(file string, v interface{}) error

ReadFile reads a file and unmarshals the content into the JSON object.

func ReadFileMaybeJSON

func ReadFileMaybeJSON(file string, v interface{}) error

ReadFileMaybeJSON reads a file that might be JSONx or JSON.

func Sprint

func Sprint(v interface{}) (string, error)

Sprint formats v in JSONX and returns the formatted string.

func ToJSON

func ToJSON(input []byte) ([]byte, []*lexing.Error)

ToJSON converts a JSONX stream into a JSON stream.

func Unmarshal

func Unmarshal(bs []byte, v interface{}) error

Unmarshal unmarshals a value into a JSON object. When there is an error on parsing JSONx, v is always unchagned.

func WriteFile

func WriteFile(p string, v interface{}) error

WriteFile writes a JSONX object into a file.

Types

type Decoder

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

Decoder is a decoder that is capable of parsing a stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates a new decoder that can parse a stream of jsonx objects.

func NewFileDecoder

func NewFileDecoder(name string, r io.Reader) *Decoder

NewFileDecoder creates a new decoder that can parse a stream of jsonx objects, where name is the filename.

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) []*lexing.Error

Decode decodes a JSON value from the parser. When there is error on parsing JSONx, v is always unchanged.

func (*Decoder) DecodeSeries

func (d *Decoder) DecodeSeries(tm TypeMaker) (
	[]*Typed, []*lexing.Error,
)

DecodeSeries decode a typed series. It uses strict JSON decoding.

func (*Decoder) More

func (d *Decoder) More() bool

More returns true if there is more stuff.

type TypeMaker

type TypeMaker func(t string) interface{}

TypeMaker is a function that makes an interface based on the given type.

type Typed

type Typed struct {
	Type string
	V    interface{}
	Pos  *lexing.Pos
}

Typed is an item in a typed list.

func ReadSeriesFile

func ReadSeriesFile(file string, tm TypeMaker) ([]*Typed, []*lexing.Error)

ReadSeriesFile reads a typed series.

Jump to

Keyboard shortcuts

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