Documentation
¶
Overview ¶
fluffyjson can deal with JSON fluffily.
- Compatible with encode/json and better interface than interface{}.
- Useful methods to handle JSON value such as cast, access, visit, and so on.
- Pure Go implementation.
Index ¶
- Constants
- type Accept
- type Access
- type AccessAs
- type AccessAsArray
- type AccessAsBool
- type AccessAsNull
- type AccessAsNumber
- type AccessAsObject
- type AccessAsString
- type Accessor
- type Array
- func (a *Array) Accept(visitor Visitor) error
- func (a *Array) Access(ptr ...Accessor) (JsonValue, error)
- func (a Array) AccessAsArray(ptr ...Accessor) (Array, error)
- func (a Array) AccessAsBool(ptr ...Accessor) (Bool, error)
- func (a Array) AccessAsNull(ptr ...Accessor) (Null, error)
- func (a Array) AccessAsNumber(ptr ...Accessor) (Number, error)
- func (a Array) AccessAsObject(ptr ...Accessor) (Object, error)
- func (a Array) AccessAsString(ptr ...Accessor) (String, error)
- func (a Array) AsArray() (Array, error)
- func (a Array) AsBool() (Bool, error)
- func (a Array) AsNull() (Null, error)
- func (a Array) AsNumber() (Number, error)
- func (a Array) AsObject() (Object, error)
- func (a Array) AsString() (String, error)
- func (v *Array) BreadthFirst() iter.Seq2[Pointer, JsonValue]
- func (v *Array) DepthFirst() iter.Seq2[Pointer, JsonValue]
- func (a Array) IsArray() bool
- func (a Array) IsBool() bool
- func (a Array) IsNull() bool
- func (a Array) IsNumber() bool
- func (a Array) IsObject() bool
- func (a Array) IsString() bool
- func (a Array) MarshalJSON() ([]byte, error)
- func (a *Array) Slice(acc SliceAccessor) ([]JsonValue, error)
- func (a Array) SliceAsArray(acc SliceAccessor) ([]Array, error)
- func (a Array) SliceAsBool(acc SliceAccessor) ([]Bool, error)
- func (a Array) SliceAsNull(acc SliceAccessor) ([]Null, error)
- func (a Array) SliceAsNumber(acc SliceAccessor) ([]Number, error)
- func (a Array) SliceAsObject(acc SliceAccessor) ([]Object, error)
- func (a Array) SliceAsString(acc SliceAccessor) ([]String, error)
- func (a *Array) UnmarshalJSON(data []byte) error
- type As
- type AsArray
- type AsBool
- type AsNull
- type AsNumber
- type AsObject
- type AsString
- type BaseVisitor
- func (bv *BaseVisitor) GetPointer() Pointer
- func (bv *BaseVisitor) LeaveArray(a *Array) error
- func (bv *BaseVisitor) LeaveArrayEntry(idx int, val JsonValue) error
- func (bv *BaseVisitor) LeaveObject(o *Object) error
- func (bv *BaseVisitor) LeaveObjectEntry(key string, val JsonValue) error
- func (bv *BaseVisitor) LeaveRoot(v *RootValue) error
- func (bv *BaseVisitor) SetPointer(Pointer)
- func (bv *BaseVisitor) VisitArray(a *Array) error
- func (bv *BaseVisitor) VisitArrayEntry(idx int, val JsonValue) error
- func (bv *BaseVisitor) VisitBool(b *Bool) error
- func (bv *BaseVisitor) VisitNull(n *Null) error
- func (bv *BaseVisitor) VisitNumber(n *Number) error
- func (bv *BaseVisitor) VisitObject(o *Object) error
- func (bv *BaseVisitor) VisitObjectEntry(key string, val JsonValue) error
- func (bv *BaseVisitor) VisitRoot(v *RootValue) error
- func (bv *BaseVisitor) VisitString(s *String) error
- type Bfs
- func (bfs *Bfs[V]) GetPointer() Pointer
- func (bfs *Bfs[V]) LeaveArray(a *Array) error
- func (bfs *Bfs[V]) LeaveArrayEntry(i int, v JsonValue) error
- func (bfs *Bfs[V]) LeaveObject(o *Object) error
- func (bfs *Bfs[V]) LeaveObjectEntry(k string, v JsonValue) error
- func (bfs *Bfs[V]) LeaveRoot(v *RootValue) error
- func (bfs *Bfs[V]) SetPointer(p Pointer)
- func (bfs *Bfs[V]) VisitArray(a *Array) (err error)
- func (bfs *Bfs[V]) VisitArrayEntry(i int, v JsonValue) (err error)
- func (bfs *Bfs[V]) VisitBool(b *Bool) error
- func (bfs *Bfs[V]) VisitNull(n *Null) error
- func (bfs *Bfs[V]) VisitNumber(n *Number) error
- func (bfs *Bfs[V]) VisitObject(o *Object) (err error)
- func (bfs *Bfs[V]) VisitObjectEntry(k string, v JsonValue) (err error)
- func (bfs *Bfs[V]) VisitRoot(v *RootValue) (err error)
- func (bfs *Bfs[V]) VisitString(s *String) error
- type Bool
- func (b *Bool) Accept(visitor Visitor) error
- func (b *Bool) Access(ptr ...Accessor) (JsonValue, error)
- func (b Bool) AccessAsArray(ptr ...Accessor) (Array, error)
- func (b Bool) AccessAsBool(ptr ...Accessor) (Bool, error)
- func (b Bool) AccessAsNull(ptr ...Accessor) (Null, error)
- func (b Bool) AccessAsNumber(ptr ...Accessor) (Number, error)
- func (b Bool) AccessAsObject(ptr ...Accessor) (Object, error)
- func (b Bool) AccessAsString(ptr ...Accessor) (String, error)
- func (b Bool) AsArray() (Array, error)
- func (b Bool) AsBool() (Bool, error)
- func (b Bool) AsNull() (Null, error)
- func (b Bool) AsNumber() (Number, error)
- func (b Bool) AsObject() (Object, error)
- func (b Bool) AsString() (String, error)
- func (v *Bool) BreadthFirst() iter.Seq2[Pointer, JsonValue]
- func (v *Bool) DepthFirst() iter.Seq2[Pointer, JsonValue]
- func (b Bool) IsArray() bool
- func (b Bool) IsBool() bool
- func (b Bool) IsNull() bool
- func (b Bool) IsNumber() bool
- func (b Bool) IsObject() bool
- func (b Bool) IsString() bool
- func (b Bool) MarshalJSON() ([]byte, error)
- func (b *Bool) Slice(acc SliceAccessor) ([]JsonValue, error)
- func (b Bool) SliceAsArray(acc SliceAccessor) ([]Array, error)
- func (b Bool) SliceAsBool(acc SliceAccessor) ([]Bool, error)
- func (b Bool) SliceAsNull(acc SliceAccessor) ([]Null, error)
- func (b Bool) SliceAsNumber(acc SliceAccessor) ([]Number, error)
- func (b Bool) SliceAsObject(acc SliceAccessor) ([]Object, error)
- func (b Bool) SliceAsString(acc SliceAccessor) ([]String, error)
- func (b *Bool) UnmarshalJSON(data []byte) error
- type Dfs
- func (v *Dfs[V]) GetPointer() Pointer
- func (dfs *Dfs[V]) LeaveArray(a *Array) error
- func (dfs *Dfs[V]) LeaveArrayEntry(i int, v JsonValue) error
- func (dfs *Dfs[V]) LeaveObject(o *Object) error
- func (dfs *Dfs[V]) LeaveObjectEntry(k string, v JsonValue) error
- func (dfs *Dfs[V]) LeaveRoot(v *RootValue) error
- func (v *Dfs[V]) SetPointer(p Pointer)
- func (dfs *Dfs[V]) VisitArray(a *Array) (err error)
- func (dfs *Dfs[V]) VisitArrayEntry(i int, v JsonValue) (err error)
- func (dfs *Dfs[V]) VisitBool(b *Bool) error
- func (dfs *Dfs[V]) VisitNull(n *Null) error
- func (dfs *Dfs[V]) VisitNumber(n *Number) error
- func (dfs *Dfs[V]) VisitObject(o *Object) (err error)
- func (dfs *Dfs[V]) VisitObjectEntry(k string, v JsonValue) (err error)
- func (dfs *Dfs[V]) VisitRoot(v *RootValue) (err error)
- func (dfs *Dfs[V]) VisitString(s *String) error
- type ErrAccess
- type ErrAsValue
- type ErrCast
- type ErrUnmarshal
- type IndexAccess
- type JsonValue
- type KeyAccess
- type KeyIndexAccess
- type Null
- func (n *Null) Accept(visitor Visitor) error
- func (n *Null) Access(ptr ...Accessor) (JsonValue, error)
- func (n Null) AccessAsArray(ptr ...Accessor) (Array, error)
- func (n Null) AccessAsBool(ptr ...Accessor) (Bool, error)
- func (n Null) AccessAsNull(ptr ...Accessor) (Null, error)
- func (n Null) AccessAsNumber(ptr ...Accessor) (Number, error)
- func (n Null) AccessAsObject(ptr ...Accessor) (Object, error)
- func (n Null) AccessAsString(ptr ...Accessor) (String, error)
- func (n Null) AsArray() (Array, error)
- func (n Null) AsBool() (Bool, error)
- func (n Null) AsNull() (Null, error)
- func (n Null) AsNumber() (Number, error)
- func (n Null) AsObject() (Object, error)
- func (n Null) AsString() (String, error)
- func (v *Null) BreadthFirst() iter.Seq2[Pointer, JsonValue]
- func (v *Null) DepthFirst() iter.Seq2[Pointer, JsonValue]
- func (n Null) IsArray() bool
- func (n Null) IsBool() bool
- func (n Null) IsNull() bool
- func (n Null) IsNumber() bool
- func (n Null) IsObject() bool
- func (n Null) IsString() bool
- func (n Null) MarshalJSON() ([]byte, error)
- func (n *Null) Slice(acc SliceAccessor) ([]JsonValue, error)
- func (n Null) SliceAsArray(acc SliceAccessor) ([]Array, error)
- func (n Null) SliceAsBool(acc SliceAccessor) ([]Bool, error)
- func (n Null) SliceAsNull(acc SliceAccessor) ([]Null, error)
- func (n Null) SliceAsNumber(acc SliceAccessor) ([]Number, error)
- func (n Null) SliceAsObject(acc SliceAccessor) ([]Object, error)
- func (n Null) SliceAsString(acc SliceAccessor) ([]String, error)
- func (n *Null) UnmarshalJSON(data []byte) error
- type Number
- func (n *Number) Accept(visitor Visitor) error
- func (n *Number) Access(ptr ...Accessor) (JsonValue, error)
- func (n Number) AccessAsArray(ptr ...Accessor) (Array, error)
- func (n Number) AccessAsBool(ptr ...Accessor) (Bool, error)
- func (n Number) AccessAsNull(ptr ...Accessor) (Null, error)
- func (n Number) AccessAsNumber(ptr ...Accessor) (Number, error)
- func (n Number) AccessAsObject(ptr ...Accessor) (Object, error)
- func (n Number) AccessAsString(ptr ...Accessor) (String, error)
- func (n Number) AsArray() (Array, error)
- func (n Number) AsBool() (Bool, error)
- func (n Number) AsNull() (Null, error)
- func (n Number) AsNumber() (Number, error)
- func (n Number) AsObject() (Object, error)
- func (n Number) AsString() (String, error)
- func (v *Number) BreadthFirst() iter.Seq2[Pointer, JsonValue]
- func (v *Number) DepthFirst() iter.Seq2[Pointer, JsonValue]
- func (n Number) IsArray() bool
- func (n Number) IsBool() bool
- func (n Number) IsNull() bool
- func (n Number) IsNumber() bool
- func (n Number) IsObject() bool
- func (n Number) IsString() bool
- func (n Number) MarshalJSON() ([]byte, error)
- func (n *Number) Slice(acc SliceAccessor) ([]JsonValue, error)
- func (n Number) SliceAsArray(acc SliceAccessor) ([]Array, error)
- func (n Number) SliceAsBool(acc SliceAccessor) ([]Bool, error)
- func (n Number) SliceAsNull(acc SliceAccessor) ([]Null, error)
- func (n Number) SliceAsNumber(acc SliceAccessor) ([]Number, error)
- func (n Number) SliceAsObject(acc SliceAccessor) ([]Object, error)
- func (n Number) SliceAsString(acc SliceAccessor) ([]String, error)
- func (n *Number) UnmarshalJSON(data []byte) error
- type Object
- func (o *Object) Accept(visitor Visitor) error
- func (o *Object) Access(ptr ...Accessor) (JsonValue, error)
- func (o Object) AccessAsArray(ptr ...Accessor) (Array, error)
- func (o Object) AccessAsBool(ptr ...Accessor) (Bool, error)
- func (o Object) AccessAsNull(ptr ...Accessor) (Null, error)
- func (o Object) AccessAsNumber(ptr ...Accessor) (Number, error)
- func (o Object) AccessAsObject(ptr ...Accessor) (Object, error)
- func (o Object) AccessAsString(ptr ...Accessor) (String, error)
- func (o Object) AsArray() (Array, error)
- func (o Object) AsBool() (Bool, error)
- func (o Object) AsNull() (Null, error)
- func (o Object) AsNumber() (Number, error)
- func (o Object) AsObject() (Object, error)
- func (o Object) AsString() (String, error)
- func (v *Object) BreadthFirst() iter.Seq2[Pointer, JsonValue]
- func (v *Object) DepthFirst() iter.Seq2[Pointer, JsonValue]
- func (o Object) IsArray() bool
- func (o Object) IsBool() bool
- func (o Object) IsNull() bool
- func (o Object) IsNumber() bool
- func (o Object) IsObject() bool
- func (o Object) IsString() bool
- func (o Object) MarshalJSON() ([]byte, error)
- func (o *Object) Slice(acc SliceAccessor) ([]JsonValue, error)
- func (o Object) SliceAsArray(acc SliceAccessor) ([]Array, error)
- func (o Object) SliceAsBool(acc SliceAccessor) ([]Bool, error)
- func (o Object) SliceAsNull(acc SliceAccessor) ([]Null, error)
- func (o Object) SliceAsNumber(acc SliceAccessor) ([]Number, error)
- func (o Object) SliceAsObject(acc SliceAccessor) ([]Object, error)
- func (o Object) SliceAsString(acc SliceAccessor) ([]String, error)
- func (o *Object) UnmarshalJSON(data []byte) error
- type Pointer
- type PointerVisitor
- type RootValue
- type Search
- type SliceAccess
- type SliceAccessor
- type String
- func (s *String) Accept(visitor Visitor) error
- func (s *String) Access(ptr ...Accessor) (JsonValue, error)
- func (s String) AccessAsArray(ptr ...Accessor) (Array, error)
- func (s String) AccessAsBool(ptr ...Accessor) (Bool, error)
- func (s String) AccessAsNull(ptr ...Accessor) (Null, error)
- func (s String) AccessAsNumber(ptr ...Accessor) (Number, error)
- func (s String) AccessAsObject(ptr ...Accessor) (Object, error)
- func (s String) AccessAsString(ptr ...Accessor) (String, error)
- func (s String) AsArray() (Array, error)
- func (s String) AsBool() (Bool, error)
- func (s String) AsNull() (Null, error)
- func (s String) AsNumber() (Number, error)
- func (s String) AsObject() (Object, error)
- func (s String) AsString() (String, error)
- func (v *String) BreadthFirst() iter.Seq2[Pointer, JsonValue]
- func (v *String) DepthFirst() iter.Seq2[Pointer, JsonValue]
- func (s String) IsArray() bool
- func (s String) IsBool() bool
- func (s String) IsNull() bool
- func (s String) IsNumber() bool
- func (s String) IsObject() bool
- func (s String) IsString() bool
- func (s String) MarshalJSON() ([]byte, error)
- func (s *String) Slice(acc SliceAccessor) ([]JsonValue, error)
- func (s String) SliceAsArray(acc SliceAccessor) ([]Array, error)
- func (s String) SliceAsBool(acc SliceAccessor) ([]Bool, error)
- func (s String) SliceAsNull(acc SliceAccessor) ([]Null, error)
- func (s String) SliceAsNumber(acc SliceAccessor) ([]Number, error)
- func (s String) SliceAsObject(acc SliceAccessor) ([]Object, error)
- func (s String) SliceAsString(acc SliceAccessor) ([]String, error)
- func (s *String) UnmarshalJSON(data []byte) error
- type ValueVisitor
- func (vv *ValueVisitor) VisitArray(a *Array) error
- func (vv *ValueVisitor) VisitBool(b *Bool) error
- func (vv *ValueVisitor) VisitNull(n *Null) error
- func (vv *ValueVisitor) VisitNumber(n *Number) error
- func (vv *ValueVisitor) VisitObject(o *Object) error
- func (vv *ValueVisitor) VisitString(s *String) error
- type Visitor
Examples ¶
Constants ¶
View Source
const ( OBJECT representation = "object" ARRAY representation = "array" STRING representation = "string" NUMBER representation = "number" BOOL representation = "bool" NULL representation = "null" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessAs ¶
type AccessAs interface {
Access
AccessAsObject
AccessAsArray
AccessAsString
AccessAsNumber
AccessAsBool
AccessAsNull
}
type AccessAsArray ¶
type AccessAsBool ¶
type AccessAsNull ¶
type AccessAsNumber ¶
type AccessAsObject ¶
type AccessAsString ¶
type Array ¶
type Array []JsonValue
func (Array) MarshalJSON ¶
func (Array) SliceAsArray ¶
func (a Array) SliceAsArray(acc SliceAccessor) ([]Array, error)
func (Array) SliceAsBool ¶
func (a Array) SliceAsBool(acc SliceAccessor) ([]Bool, error)
func (Array) SliceAsNull ¶
func (a Array) SliceAsNull(acc SliceAccessor) ([]Null, error)
func (Array) SliceAsNumber ¶
func (a Array) SliceAsNumber(acc SliceAccessor) ([]Number, error)
func (Array) SliceAsObject ¶
func (a Array) SliceAsObject(acc SliceAccessor) ([]Object, error)
func (Array) SliceAsString ¶
func (a Array) SliceAsString(acc SliceAccessor) ([]String, error)
func (*Array) UnmarshalJSON ¶
type BaseVisitor ¶
type BaseVisitor struct{}
func (*BaseVisitor) GetPointer ¶
func (bv *BaseVisitor) GetPointer() Pointer
func (*BaseVisitor) LeaveArray ¶
func (bv *BaseVisitor) LeaveArray(a *Array) error
func (*BaseVisitor) LeaveArrayEntry ¶
func (bv *BaseVisitor) LeaveArrayEntry(idx int, val JsonValue) error
func (*BaseVisitor) LeaveObject ¶
func (bv *BaseVisitor) LeaveObject(o *Object) error
func (*BaseVisitor) LeaveObjectEntry ¶
func (bv *BaseVisitor) LeaveObjectEntry(key string, val JsonValue) error
func (*BaseVisitor) LeaveRoot ¶
func (bv *BaseVisitor) LeaveRoot(v *RootValue) error
func (*BaseVisitor) SetPointer ¶
func (bv *BaseVisitor) SetPointer(Pointer)
func (*BaseVisitor) VisitArray ¶
func (bv *BaseVisitor) VisitArray(a *Array) error
func (*BaseVisitor) VisitArrayEntry ¶
func (bv *BaseVisitor) VisitArrayEntry(idx int, val JsonValue) error
func (*BaseVisitor) VisitBool ¶
func (bv *BaseVisitor) VisitBool(b *Bool) error
func (*BaseVisitor) VisitNull ¶
func (bv *BaseVisitor) VisitNull(n *Null) error
func (*BaseVisitor) VisitNumber ¶
func (bv *BaseVisitor) VisitNumber(n *Number) error
func (*BaseVisitor) VisitObject ¶
func (bv *BaseVisitor) VisitObject(o *Object) error
func (*BaseVisitor) VisitObjectEntry ¶
func (bv *BaseVisitor) VisitObjectEntry(key string, val JsonValue) error
func (*BaseVisitor) VisitRoot ¶
func (bv *BaseVisitor) VisitRoot(v *RootValue) error
func (*BaseVisitor) VisitString ¶
func (bv *BaseVisitor) VisitString(s *String) error
type Bfs ¶
type Bfs[V Visitor] struct { // contains filtered or unexported fields }
func (*Bfs[V]) GetPointer ¶
func (bfs *Bfs[V]) GetPointer() Pointer
func (*Bfs[V]) LeaveArray ¶
func (*Bfs[V]) LeaveArrayEntry ¶
func (*Bfs[V]) LeaveObject ¶
func (*Bfs[V]) LeaveObjectEntry ¶
func (*Bfs[V]) SetPointer ¶
func (bfs *Bfs[V]) SetPointer(p Pointer)
func (*Bfs[V]) VisitArray ¶
func (*Bfs[V]) VisitArrayEntry ¶
func (*Bfs[V]) VisitNumber ¶
func (*Bfs[V]) VisitObject ¶
func (*Bfs[V]) VisitObjectEntry ¶
func (*Bfs[V]) VisitString ¶
type Bool ¶
type Bool bool
func (Bool) MarshalJSON ¶
func (Bool) SliceAsArray ¶
func (b Bool) SliceAsArray(acc SliceAccessor) ([]Array, error)
func (Bool) SliceAsBool ¶
func (b Bool) SliceAsBool(acc SliceAccessor) ([]Bool, error)
func (Bool) SliceAsNull ¶
func (b Bool) SliceAsNull(acc SliceAccessor) ([]Null, error)
func (Bool) SliceAsNumber ¶
func (b Bool) SliceAsNumber(acc SliceAccessor) ([]Number, error)
func (Bool) SliceAsObject ¶
func (b Bool) SliceAsObject(acc SliceAccessor) ([]Object, error)
func (Bool) SliceAsString ¶
func (b Bool) SliceAsString(acc SliceAccessor) ([]String, error)
func (*Bool) UnmarshalJSON ¶
type Dfs ¶
type Dfs[V Visitor] struct { // contains filtered or unexported fields }
func (*Dfs[V]) GetPointer ¶
func (*Dfs[V]) LeaveArray ¶
func (*Dfs[V]) LeaveObject ¶
func (*Dfs[V]) SetPointer ¶
func (*Dfs[V]) VisitArray ¶
func (*Dfs[V]) VisitNumber ¶
func (*Dfs[V]) VisitObject ¶
func (*Dfs[V]) VisitObjectEntry ¶
func (*Dfs[V]) VisitString ¶
type ErrAccess ¶
type ErrAccess struct {
Accessor string
Expected representation
Actual representation
}
type ErrAsValue ¶
type ErrAsValue struct {
Expected representation
Actual representation
}
func (ErrAsValue) Error ¶
func (e ErrAsValue) Error() string
type ErrUnmarshal ¶
type ErrUnmarshal struct {
Data []byte
}
func (ErrUnmarshal) Error ¶
func (e ErrUnmarshal) Error() string
type IndexAccess ¶
type IndexAccess int
type JsonValue ¶
type JsonValue interface {
json.Unmarshaler // TODO this cause pointer receiver
json.Marshaler
As
Access
AccessAs
Accept
Search
// contains filtered or unexported methods
}
The interface of JSON(https://www.json.org/) value
type KeyIndexAccess ¶
type KeyIndexAccess string
type Null ¶
type Null func(null)
func (Null) MarshalJSON ¶
func (Null) SliceAsArray ¶
func (n Null) SliceAsArray(acc SliceAccessor) ([]Array, error)
func (Null) SliceAsBool ¶
func (n Null) SliceAsBool(acc SliceAccessor) ([]Bool, error)
func (Null) SliceAsNull ¶
func (n Null) SliceAsNull(acc SliceAccessor) ([]Null, error)
func (Null) SliceAsNumber ¶
func (n Null) SliceAsNumber(acc SliceAccessor) ([]Number, error)
func (Null) SliceAsObject ¶
func (n Null) SliceAsObject(acc SliceAccessor) ([]Object, error)
func (Null) SliceAsString ¶
func (n Null) SliceAsString(acc SliceAccessor) ([]String, error)
func (*Null) UnmarshalJSON ¶
type Number ¶
type Number float64
func CastNumber ¶
func (Number) MarshalJSON ¶
func (Number) SliceAsArray ¶
func (n Number) SliceAsArray(acc SliceAccessor) ([]Array, error)
func (Number) SliceAsBool ¶
func (n Number) SliceAsBool(acc SliceAccessor) ([]Bool, error)
func (Number) SliceAsNull ¶
func (n Number) SliceAsNull(acc SliceAccessor) ([]Null, error)
func (Number) SliceAsNumber ¶
func (n Number) SliceAsNumber(acc SliceAccessor) ([]Number, error)
func (Number) SliceAsObject ¶
func (n Number) SliceAsObject(acc SliceAccessor) ([]Object, error)
func (Number) SliceAsString ¶
func (n Number) SliceAsString(acc SliceAccessor) ([]String, error)
func (*Number) UnmarshalJSON ¶
type Object ¶
func (Object) MarshalJSON ¶
func (Object) SliceAsArray ¶
func (o Object) SliceAsArray(acc SliceAccessor) ([]Array, error)
func (Object) SliceAsBool ¶
func (o Object) SliceAsBool(acc SliceAccessor) ([]Bool, error)
func (Object) SliceAsNull ¶
func (o Object) SliceAsNull(acc SliceAccessor) ([]Null, error)
func (Object) SliceAsNumber ¶
func (o Object) SliceAsNumber(acc SliceAccessor) ([]Number, error)
func (Object) SliceAsObject ¶
func (o Object) SliceAsObject(acc SliceAccessor) ([]Object, error)
func (Object) SliceAsString ¶
func (o Object) SliceAsString(acc SliceAccessor) ([]String, error)
func (*Object) UnmarshalJSON ¶
type PointerVisitor ¶
type PointerVisitor struct {
BaseVisitor
// contains filtered or unexported fields
}
func (*PointerVisitor) GetPointer ¶
func (bv *PointerVisitor) GetPointer() Pointer
func (*PointerVisitor) SetPointer ¶
func (bv *PointerVisitor) SetPointer(p Pointer)
type RootValue ¶
type RootValue struct{ JsonValue }
Example (AsMethods) ¶
package main
import (
"encoding/json"
"fmt"
fluffyjson "github.com/hayas1/go-fluffy-json"
)
func main() {
target := `{"hello":"world"}`
var value fluffyjson.RootValue
if err := json.Unmarshal([]byte(target), &value); err != nil {
panic(err)
}
object, err := value.AccessAsObject()
if err != nil {
panic(err)
}
world, err := object["hello"].AccessAsString()
if err != nil {
panic(err)
}
match := world == "world"
if !match {
panic("not world")
}
fmt.Println(match)
}
Output: true
Example (SwitchSyntax) ¶
package main
import (
"encoding/json"
"fmt"
fluffyjson "github.com/hayas1/go-fluffy-json"
)
func main() {
target := `{"hello":"world"}`
var value fluffyjson.RootValue
if err := json.Unmarshal([]byte(target), &value); err != nil {
panic(err)
}
switch object := value.JsonValue.(type) {
// case SomeType:
// panic("fail to compile: the interface is not implemented for SomeType basically")
case *fluffyjson.Object:
switch world := (*object)["hello"].(type) {
case *fluffyjson.String:
if match := *world == "world"; !match {
panic("not world")
} else {
fmt.Println(match)
}
default:
panic("not string")
}
default:
panic("not object")
}
}
Output: true
func (*RootValue) DepthFirst ¶
Example ¶
package main
import (
"encoding/json"
"fmt"
fluffyjson "github.com/hayas1/go-fluffy-json"
)
func main() {
target := `[[[1,2],[3,4]],[[5,6],[7,8]]]`
var value fluffyjson.RootValue
if err := json.Unmarshal([]byte(target), &value); err != nil {
panic(err)
}
var sum func(v fluffyjson.JsonValue) int
sum = func(v fluffyjson.JsonValue) int {
switch t := v.(type) {
case *fluffyjson.Array:
s := 0
for _, vv := range *t {
s += sum(vv)
}
return s
case *fluffyjson.Number:
return int(*t)
default:
panic("not array or number")
}
}
results := make([]int, 0, 15)
for _, v := range value.DepthFirst() {
results = append(results, sum(v))
}
fmt.Println(results)
}
Output: [36 10 3 1 2 7 3 4 26 11 5 6 15 7 8]
func (RootValue) MarshalJSON ¶
Example ¶
package main
import (
"fmt"
fluffyjson "github.com/hayas1/go-fluffy-json"
)
func main() {
v := fluffyjson.RootValue{&fluffyjson.Array{
&[]fluffyjson.String{fluffyjson.String("hello")}[0],
&[]fluffyjson.String{fluffyjson.String("world")}[0],
}}
b, err := v.MarshalJSON()
if err != nil {
panic(err)
}
fmt.Println(string(b))
}
Output: ["hello","world"]
func (*RootValue) UnmarshalJSON ¶
Example ¶
package main
import (
"encoding/json"
"fmt"
fluffyjson "github.com/hayas1/go-fluffy-json"
)
func main() {
var v struct {
Fluffy fluffyjson.RootValue `json:"fluffy"`
}
if err := json.Unmarshal([]byte(`{"fluffy":{"deep":{"nested":{"json":{"value":["hello","world"]}}}}}`), &v); err != nil {
panic(err)
}
pointer, err := fluffyjson.ParsePointer("/deep/nested/json/value/1")
if err != nil {
panic(err)
}
world, err := v.Fluffy.AccessAsString(pointer)
if err != nil {
panic(err)
}
fmt.Println(world)
}
Output: world
type SliceAccess ¶
type SliceAccessor ¶
type String ¶
type String string
func CastString ¶
func (String) MarshalJSON ¶
func (String) SliceAsArray ¶
func (s String) SliceAsArray(acc SliceAccessor) ([]Array, error)
func (String) SliceAsBool ¶
func (s String) SliceAsBool(acc SliceAccessor) ([]Bool, error)
func (String) SliceAsNull ¶
func (s String) SliceAsNull(acc SliceAccessor) ([]Null, error)
func (String) SliceAsNumber ¶
func (s String) SliceAsNumber(acc SliceAccessor) ([]Number, error)
func (String) SliceAsObject ¶
func (s String) SliceAsObject(acc SliceAccessor) ([]Object, error)
func (String) SliceAsString ¶
func (s String) SliceAsString(acc SliceAccessor) ([]String, error)
func (*String) UnmarshalJSON ¶
type ValueVisitor ¶
type ValueVisitor struct {
PointerVisitor
// contains filtered or unexported fields
}
func (*ValueVisitor) VisitArray ¶
func (vv *ValueVisitor) VisitArray(a *Array) error
func (*ValueVisitor) VisitBool ¶
func (vv *ValueVisitor) VisitBool(b *Bool) error
func (*ValueVisitor) VisitNull ¶
func (vv *ValueVisitor) VisitNull(n *Null) error
func (*ValueVisitor) VisitNumber ¶
func (vv *ValueVisitor) VisitNumber(n *Number) error
func (*ValueVisitor) VisitObject ¶
func (vv *ValueVisitor) VisitObject(o *Object) error
func (*ValueVisitor) VisitString ¶
func (vv *ValueVisitor) VisitString(s *String) error
type Visitor ¶
type Visitor interface {
GetPointer() Pointer
SetPointer(Pointer)
VisitRoot(*RootValue) error
LeaveRoot(*RootValue) error
VisitObject(*Object) error
VisitObjectEntry(string, JsonValue) error
LeaveObjectEntry(string, JsonValue) error
LeaveObject(*Object) error
VisitArray(*Array) error
VisitArrayEntry(int, JsonValue) error
LeaveArrayEntry(int, JsonValue) error
LeaveArray(*Array) error
VisitString(*String) error
VisitNumber(*Number) error
VisitBool(*Bool) error
VisitNull(*Null) error
}
Click to show internal directories.
Click to hide internal directories.