Documentation
¶
Overview ¶
Package fson provides a way to interact with arbitrary JSON fields as well as use JSON(b) within Postgresql Fson supports the json interfaces MarshalJSON/UnmarshalJSON as well as the Scan interface within the db packages
Index ¶
- type FilterFn
- type FmapFn
- type Fson
- func (f *Fson) Bytes() []byte
- func (f *Fson) Del(path []string)
- func (f *Fson) Exists(path ...string) bool
- func (f *Fson) Filter(fn FilterFn)
- func (f *Fson) Fmap(fn FmapFn)
- func (f *Fson) Get(path ...string) (interface{}, bool)
- func (f *Fson) GetArray(path ...string) ([]interface{}, bool)
- func (f *Fson) GetBool(path ...string) (bool, bool)
- func (f *Fson) GetFloat(path ...string) (float64, bool)
- func (f *Fson) GetInt(path ...string) (int, bool)
- func (f *Fson) GetObject(path ...string) (*Fson, bool)
- func (f *Fson) GetString(path ...string) (string, bool)
- func (f *Fson) Loads(b []byte) error
- func (f *Fson) MarshalJSON() ([]byte, error)
- func (f *Fson) Merge(obj *Fson)
- func (f *Fson) Pretty() string
- func (f *Fson) Scan(src interface{}) error
- func (f *Fson) Set(value interface{}, path ...string)
- func (f *Fson) SetA(value interface{}, path ...string)
- func (f *Fson) String() string
- func (f *Fson) UnmarshalJSON(b []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FilterFn ¶
type FilterFn func(interface{}) bool
FilterFn is the interface returning a boolean value of whether to include this value. This will change the JSON structure
type FmapFn ¶
type FmapFn func(interface{}) interface{}
FmapFn will transform a value within the JSON into a new value, leaving the JSON structure alone
type Fson ¶
type Fson struct {
Data map[string]interface{}
}
Fson struct is the core structure, no exported members
func (*Fson) Bytes ¶
Bytes will return a byte slice of the underlying JSON data. If there is an error an empty byte slice is returned
func (*Fson) Filter ¶
Filter will filter out values from the JSON where the f "filterFn" returns false for that value
func (*Fson) Fmap ¶
Fmap applys a function to every value in the JSON structure, mutating them in place
func (*Fson) Get ¶
Get works like set in that the path to the key is specified as a list of string values which represent the orderd nested object keys
func (*Fson) GetArray ¶
GetArray will retrieve an array item from a specific key in the Fson object. The JSON array will be returned as a slice of interface{}
func (*Fson) GetBool ¶
GetBool will check if the key exists, and if the key is an bool it will return it
func (*Fson) GetFloat ¶
GetFloat will check if the key exists, and if the key is an float64 it will return it
func (*Fson) GetInt ¶
GetInt will check if the key exists, and if the key is an integer it will return it
func (*Fson) GetObject ¶
GetObject will work the same as Get except this will automatically encode the result into an Fson object. If the value retrieved is not a JSON object, this will return nil, false
func (*Fson) GetString ¶
GetString will check if the key exists and if the key is a string, if so, returns the (string, true), else ("", false)
func (*Fson) Loads ¶
Loads will take nil or a []byte array and create a Fson object with it. Generally nil is used if you want to build your JSON object from scratch with the Set method This will overwrite any current data that is in the Fson object
func (*Fson) MarshalJSON ¶
MarshalJSON implementation for JSON encoding
func (*Fson) Merge ¶
Merge will take two an Fson object and merge it with an existing Fson object. The new object will overwrite any matching key values
func (*Fson) Set ¶
Set will set a value to a specified path. The path is defined as a variadic parameter. This will overwrite any value that is located at the provided key
func (*Fson) SetA ¶
SetA is the same as set except that it will append to a list. If no list exists, it will create a list. If an element currently exists, a new list will be created with the existing element as the head of the list.
func (*Fson) UnmarshalJSON ¶
UnmarshalJSON impelmentation for JSON decoding to Fson
