libjson

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: BSD-3-Clause Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultPackageName = "json"

DeafultPackageName is the package name used by LoadPackage.

Variables

This section is empty.

Functions

func Builtins

func Builtins(s *Serializer) []*libutil.Builtin

Builtins takes the default serializer for a lisp environment and returns a set of package builtin functions that use it.

func Dump

func Dump(v *lisp.LVal, stringNums bool) ([]byte, error)

Dump serializes the structure of v as a JSON formatted byte slice.

func Load

func Load(b []byte, stringNums bool) *lisp.LVal

Load parses b as JSON and returns an equivalent LVal.

func LoadPackage

func LoadPackage(env *lisp.LEnv) *lisp.LVal

LoadPackage adds the time package to env

Types

type Serializer

type Serializer struct {
	UseStringNumbers bool
	True             *lisp.LVal
	False            *lisp.LVal
	Null             *lisp.LVal
}

Serializer defines JSON serialization rules for lisp values.

func DefaultSerializer

func DefaultSerializer() *Serializer

func (*Serializer) Dump

func (s *Serializer) Dump(v *lisp.LVal, stringNums bool) ([]byte, error)

Dump serializes v as JSON and returns any error.

func (*Serializer) DumpBytesBuiltin

func (s *Serializer) DumpBytesBuiltin(env *lisp.LEnv, args *lisp.LVal) *lisp.LVal

func (*Serializer) DumpMessageBuiltin

func (s *Serializer) DumpMessageBuiltin(env *lisp.LEnv, args *lisp.LVal) *lisp.LVal

func (*Serializer) DumpStringBuiltin

func (s *Serializer) DumpStringBuiltin(env *lisp.LEnv, args *lisp.LVal) *lisp.LVal

func (*Serializer) GoError

func (s *Serializer) GoError(v *lisp.LVal) error

GoError returns an error that represents v. If v is not LError then nil is returned.

func (*Serializer) GoFloat64

func (s *Serializer) GoFloat64(v *lisp.LVal) (float64, bool)

GoFloat64 converts the numeric value that v represents to a float64 and returns it with the value true. If v does not represent a number GoFloat64 returns a false second argument

func (*Serializer) GoInt

func (s *Serializer) GoInt(v *lisp.LVal) (int, bool)

GoInt converts the numeric value that v represents to and int and returns it with the value true. If v does not represent a number GoInt returns a false second argument

func (*Serializer) GoMap

func (s *Serializer) GoMap(v *lisp.LVal, stringNums bool) (SortedMap, bool)

GoMap converts an LSortMap to its Go equivalent and returns it with a true second argument. If v does not represent a map json serializable map GoMap returns a false second argument

func (*Serializer) GoSlice

func (s *Serializer) GoSlice(v *lisp.LVal, stringNums bool) ([]interface{}, bool)

GoSlice returns the string that v represents and the value true. If v does not represent a string GoSlice returns a false second argument

func (*Serializer) GoString

func (s *Serializer) GoString(v *lisp.LVal) (string, bool)

GoString returns the string that v represents and the value true. If v does not represent a string GoString returns a false second argument

func (*Serializer) GoValue

func (s *Serializer) GoValue(v *lisp.LVal, stringNums bool) interface{}

GoValue converts v to its natural representation in Go. Quotes are ignored and all lists are turned into slices. Symbols are converted to strings. The value Nil() is converted to nil. Functions are returned as is.

func (*Serializer) Load

func (s *Serializer) Load(b []byte, stringNums bool) *lisp.LVal

Load parses b and returns an LVal representing its structure.

func (*Serializer) LoadBytesBuiltin

func (s *Serializer) LoadBytesBuiltin(env *lisp.LEnv, args *lisp.LVal) *lisp.LVal

func (*Serializer) LoadMessageBuiltin

func (s *Serializer) LoadMessageBuiltin(env *lisp.LEnv, args *lisp.LVal) *lisp.LVal

func (*Serializer) LoadStringBuiltin

func (s *Serializer) LoadStringBuiltin(env *lisp.LEnv, args *lisp.LVal) *lisp.LVal

func (*Serializer) MessageBytesBuiltin

func (s *Serializer) MessageBytesBuiltin(env *lisp.LEnv, args *lisp.LVal) *lisp.LVal

func (*Serializer) SymbolName

func (s *Serializer) SymbolName(v *lisp.LVal) (string, bool)

SymbolName returns the name of the symbol that v represents and the value true. If v does not represent a symbol SymbolName returns a false second argument

func (*Serializer) UseStringNumbersBuiltin

func (s *Serializer) UseStringNumbersBuiltin(env *lisp.LEnv, args *lisp.LVal) *lisp.LVal

type SortedMap

type SortedMap map[string]interface{}

func (SortedMap) MarshalJSON

func (m SortedMap) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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