json

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: GPL-3.0 Imports: 13 Imported by: 17

Documentation

Index

Constants

View Source
const (
	ObjectKind = iota
	ArrayKind
)
View Source
const (
	JsonKind = iota
	StringKind
	IntegerKind
	FloatKind
	BoolKind
	NullKind
)

Variables

This section is empty.

Functions

func ApplyTo

func ApplyTo(j Json, obj interface{}) bool

ApplyTo modifies 'obj' according to 'j'; warning: 'obj' must be a pointer to a global, exported and modifiable record variable of its module, and only its exported and modifiable fields are taken into account.

func DecodeString

func DecodeString(s string) string

func GetBool

func GetBool(v Value) (bool, bool)

func GetFloat

func GetFloat(v Value) (float64, bool)

func GetInt

func GetInt(v Value) (int64, bool)

func GetLength

func GetLength(a *Array) int

func GetNull

func GetNull(v Value) bool

func GetString

func GetString(v Value) (string, bool)

func SetElem added in v1.0.7

func SetElem(a *Array, num int, value Value) bool

func SetRComp

func SetRComp(rComp io.Reader)

func SetValue added in v1.0.7

func SetValue(o *Object, name string, value Value)

Types

type Array

type Array struct {
	Elements Values
}

func (*Array) GetArray

func (a *Array) GetArray() *Array

func (*Array) GetFlatString

func (a *Array) GetFlatString() string

func (*Array) GetObject

func (a *Array) GetObject() *Object

func (*Array) GetString

func (a *Array) GetString() string

func (*Array) JKind

func (*Array) JKind() int

func (*Array) Write

func (a *Array) Write(w io.Writer)

'Write' writes 'a' with 'w'

func (*Array) WriteFlat

func (a *Array) WriteFlat(w io.Writer)

'WriteFlat' writes 'a' with 'w'

type Bool

type Bool struct {
	Bool bool
}

func (*Bool) VKind

func (*Bool) VKind() int

type Field

type Field struct {
	Name  string
	Value Value
}

type Fields

type Fields []*Field

type Float

type Float struct {
	F float64
}

func (*Float) VKind

func (*Float) VKind() int

type Integer

type Integer struct {
	N int64
}

func (*Integer) VKind

func (*Integer) VKind() int

type Json

type Json interface {
	JKind() int

	GetObject() *Object

	GetArray() *Array

	// 'GetString' returns a formatted string for reading
	GetString() string

	// 'GetFlatString' returns a compact string
	GetFlatString() string

	// 'Write' writes 'GetString()' to 'w'
	Write(w io.Writer)

	// 'WriteFlat' writes 'GetFlatString' to 'w'
	WriteFlat(w io.Writer)
}

A Json may be an 'Object' or an 'Array'

func BuildJsonFrom

func BuildJsonFrom(obj interface{}) Json

BuildJsonFrom builds and returns a Json describing obj; warning: obj must be nil or a pointer to a global exported struct variable of its package, and only its exported fields are taken into account

func Compile

func Compile(rs io.ReadSeeker) Json

'Compile' builds a Json from an 'io.ReadSeeker'

func GetJson

func GetJson(v Value) (Json, bool)

func ReadFile

func ReadFile(path string) Json

os.File -> Json

func ReadRSC

func ReadRSC(rsc ReadSeekCloser) Json

ReadSeekCloser -> Json

func ReadString

func ReadString(s string) Json

string -> Json

type JsonVal

type JsonVal struct {
	Json Json
}

func (*JsonVal) VKind

func (*JsonVal) VKind() int

type Maker

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

A 'Maker' builds Json by stack manipulation

func NewMaker

func NewMaker() *Maker

func (*Maker) BuildArray

func (m *Maker) BuildArray()

'BuildArray' builds a json array from all the values stacked from the last 'StartArray' call and stacks it

func (*Maker) BuildField

func (m *Maker) BuildField(name string)

'BuildField' builds the json object field whose name is 'name' and whose value is the last element on the stack and replaces this element with the built field

func (*Maker) BuildObject

func (m *Maker) BuildObject()

'BuildObject' builds a json object from all the fields stacked from the last 'StartObject' call and stacks it

func (*Maker) GetJson

func (m *Maker) GetJson() Json

GetJson builds and returns a Json built from the last object on the stack

func (*Maker) PushBoolean

func (m *Maker) PushBoolean(b bool)

'PushBoolean' pushes the boolean 'b' on the stack

func (*Maker) PushField

func (m *Maker) PushField(f *Field)

'PushField' pushes the field 'f' on the stack

func (*Maker) PushFloat

func (m *Maker) PushFloat(f float64)

'PushReal' pushes the float 'f' on the stack

func (*Maker) PushInteger

func (m *Maker) PushInteger(n int64)

'PushInteger' pushes the integer 'n' on the stack

func (*Maker) PushJson

func (m *Maker) PushJson(j Json)

'PushJson' pushes the Json 'j' on the stack

func (*Maker) PushNull

func (m *Maker) PushNull()

'PushNull' pushes a json null value on the stack

func (*Maker) PushString

func (m *Maker) PushString(s string)

'PushString' pushes the string 's' on the stack

func (*Maker) PushValue

func (m *Maker) PushValue(v Value)

'PushValue' pushes the value 'v' on the stack

func (*Maker) Roll

func (m *Maker) Roll(n int)

stack[1] <- stack[n]

func (*Maker) RollD

func (m *Maker) RollD(n int)

stack[n] <- stack[1]

func (*Maker) StartArray

func (m *Maker) StartArray()

'StartArray' begins a json array

func (*Maker) StartObject

func (m *Maker) StartObject()

'StartObject' begins a json object

func (*Maker) Swap

func (m *Maker) Swap()

stack[2] <-> stack[1]

type Null

type Null struct {
}

func (*Null) VKind

func (*Null) VKind() int

type Object

type Object struct {
	Fields Fields
}

func (*Object) GetArray

func (o *Object) GetArray() *Array

func (*Object) GetFlatString

func (o *Object) GetFlatString() string

func (*Object) GetObject

func (o *Object) GetObject() *Object

func (*Object) GetString

func (o *Object) GetString() string

func (*Object) JKind

func (*Object) JKind() int

func (*Object) Write

func (o *Object) Write(w io.Writer)

'Write' writes 'o' with 'w'

func (*Object) WriteFlat

func (o *Object) WriteFlat(w io.Writer)

'WriteFlat' writes 'o' with 'w'

type ReadSeekCloser

type ReadSeekCloser interface {
	io.ReadCloser
	io.Seeker
}

type String

type String struct {
	S string
}

func (*String) VKind

func (*String) VKind() int

type Value

type Value interface {
	VKind() int
}

func GetElem

func GetElem(a *Array, num int) (Value, bool)

func GetValue

func GetValue(o *Object, name string) (Value, bool)

func SetBool added in v1.0.7

func SetBool(b bool) Value

func SetFloat added in v1.0.7

func SetFloat(f float64) Value

func SetInt added in v1.0.7

func SetInt(n int64) Value

func SetJson added in v1.0.7

func SetJson(j Json) Value

func SetNull added in v1.0.7

func SetNull() Value

func SetString added in v1.0.7

func SetString(s string) Value

type Values

type Values []Value

Directories

Path Synopsis
The package json is an implementation of the JSON language This package must be imported for its side effects when the JSON compiler is stored in "util/json/static" (file "compVar.go", variable "compiler")
The package json is an implementation of the JSON language This package must be imported for its side effects when the JSON compiler is stored in "util/json/static" (file "compVar.go", variable "compiler")

Jump to

Keyboard shortcuts

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