Documentation ¶
Overview ¶
Package gabs implements a simplified wrapper around creating and parsing JSON.
Index ¶
- Variables
- func GetFieldValueFromIn(data interface{}, mappingField *field.MappingField) (interface{}, error)
- func GetFieldValueFromInP(data interface{}, path string) (interface{}, error)
- func SetFieldValue(data interface{}, jsonData interface{}, mappingField *field.MappingField) (interface{}, error)
- func SetFieldValueFromString(data interface{}, jsonData string, mappingField *field.MappingField) (interface{}, error)
- func SetFieldValueFromStringP(data interface{}, jsonData string, path string) (interface{}, error)
- func SetFieldValueP(data interface{}, jsonData interface{}, path string) (interface{}, error)
- type Container
- func (g *Container) Array(path ...string) (*Container, error)
- func (g *Container) ArrayAppend(value interface{}, path ...string) error
- func (g *Container) ArrayAppendP(value interface{}, path string) error
- func (g *Container) ArrayCount(path ...string) (int, error)
- func (g *Container) ArrayCountP(path string) (int, error)
- func (g *Container) ArrayElement(index int, path ...string) (*Container, error)
- func (g *Container) ArrayElementP(index int, path string) (*Container, error)
- func (g *Container) ArrayI(index int) (*Container, error)
- func (g *Container) ArrayOfSize(size int, path ...string) (*Container, error)
- func (g *Container) ArrayOfSizeI(size, index int) (*Container, error)
- func (g *Container) ArrayOfSizeP(size int, path string) (*Container, error)
- func (g *Container) ArrayP(path string) (*Container, error)
- func (g *Container) ArrayRemove(index int, path ...string) error
- func (g *Container) ArrayRemoveP(index int, path string) error
- func (g *Container) Bytes() []byte
- func (g *Container) BytesIndent(prefix string, indent string) []byte
- func (g *Container) Children() ([]*Container, error)
- func (g *Container) ChildrenMap() (map[string]*Container, error)
- func (g *Container) Data() interface{}
- func (g *Container) Delete(path ...string) error
- func (g *Container) DeleteP(path string) error
- func (g *Container) Exists(hierarchy ...string) bool
- func (g *Container) ExistsP(path string) bool
- func (g *Container) Index(index int) *Container
- func (g *Container) Object(path ...string) (*Container, error)
- func (g *Container) ObjectI(index int) (*Container, error)
- func (g *Container) ObjectP(path string) (*Container, error)
- func (g *Container) Path(path string) *Container
- func (g *Container) S(hierarchy ...string) *Container
- func (g *Container) Search(hierarchy ...string) *Container
- func (g *Container) Set(value interface{}, path ...string) (*Container, error)
- func (g *Container) SetIndex(value interface{}, index int) (*Container, error)
- func (g *Container) SetP(value interface{}, path string) (*Container, error)
- func (g *Container) String() string
- func (g *Container) StringIndent(prefix string, indent string) string
- type JSONData
Constants ¶
This section is empty.
Variables ¶
var ( // ErrOutOfBounds - Index out of bounds. ErrOutOfBounds = errors.New("out of bounds") // ErrNotObjOrArray - The target is not an object or array type. ErrNotObjOrArray = errors.New("not an object or array") // ErrNotObj - The target is not an object type. ErrNotObj = errors.New("not an object") // ErrNotArray - The target is not an array type. ErrNotArray = errors.New("not an array") // ErrPathCollision - Creating a path failed because an element collided with an existing value. ErrPathCollision = errors.New("encountered value collision whilst building path") // ErrInvalidInputObj - The input value was not a map[string]interface{}. ErrInvalidInputObj = errors.New("invalid input object") // ErrInvalidInputText - The input data could not be parsed. ErrInvalidInputText = errors.New("input text could not be parsed") // ErrInvalidPath - The filepath was not valid. ErrInvalidPath = errors.New("invalid file path") // ErrInvalidBuffer - The input buffer contained an invalid JSON string ErrInvalidBuffer = errors.New("input buffer contained invalid JSON") )
Functions ¶
func GetFieldValueFromIn ¶
func GetFieldValueFromIn(data interface{}, mappingField *field.MappingField) (interface{}, error)
func GetFieldValueFromInP ¶
func SetFieldValue ¶
func SetFieldValue(data interface{}, jsonData interface{}, mappingField *field.MappingField) (interface{}, error)
func SetFieldValueFromString ¶
func SetFieldValueFromString(data interface{}, jsonData string, mappingField *field.MappingField) (interface{}, error)
func SetFieldValueP ¶
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container - an internal structure that holds a reference to the core interface map of the parsed json. Use this container to move context.
func Consume ¶
Consume - Gobble up an already converted JSON object, or a fresh map[string]interface{} object.
func ParseJSONBuffer ¶
ParseJSONBuffer - Read the contents of a buffer into a representation of the parsed JSON.
func ParseJSONDecoder ¶
ParseJSONDecoder - Convert a json.Decoder into a representation of the parsed JSON.
func ParseJSONFile ¶
ParseJSONFile - Read a file and convert into a representation of the parsed JSON.
func (*Container) Array ¶
Array - Create a new JSON array at a path. Returns an error if the path contains a collision with a non object type.
func (*Container) ArrayAppend ¶
ArrayAppend - Append a value onto a JSON array.
func (*Container) ArrayAppendP ¶
ArrayAppendP - Append a value onto a JSON array using a dot notation JSON path.
func (*Container) ArrayCount ¶
ArrayCount - Count the number of elements in a JSON array.
func (*Container) ArrayCountP ¶
ArrayCountP - Count the number of elements in a JSON array using a dot notation JSON path.
func (*Container) ArrayElement ¶
ArrayElement - Access an element from a JSON array.
func (*Container) ArrayElementP ¶
ArrayElementP - Access an element from a JSON array using a dot notation JSON path.
func (*Container) ArrayI ¶
ArrayI - Create a new JSON array at an array index. Returns an error if the object is not an array or the index is out of bounds.
func (*Container) ArrayOfSize ¶
ArrayOfSize - Create a new JSON array of a particular size at a path. Returns an error if the path contains a collision with a non object type.
func (*Container) ArrayOfSizeI ¶
ArrayOfSizeI - Create a new JSON array of a particular size at an array index. Returns an error if the object is not an array or the index is out of bounds.
func (*Container) ArrayOfSizeP ¶
ArrayOfSizeP - Does the same as ArrayOfSize, but using a dot notation JSON path.
func (*Container) ArrayRemove ¶
ArrayRemove - Remove an element from a JSON array.
func (*Container) ArrayRemoveP ¶
ArrayRemoveP - Remove an element from a JSON array using a dot notation JSON path.
func (*Container) BytesIndent ¶
BytesIndent - Converts the contained object to a JSON []byte blob formatted with prefix, indent.
func (*Container) Children ¶
Children - Return a slice of all the children of the array. This also works for objects, however, the children returned for an object will NOT be in order and you lose the names of the returned objects this way.
func (*Container) ChildrenMap ¶
ChildrenMap - Return a map of all the children of an object.
func (*Container) Data ¶
func (g *Container) Data() interface{}
Data - Return the contained data as an interface{}.
func (*Container) Delete ¶
Delete - Delete an element at a JSON path, an error is returned if the element does not exist.
func (*Container) Index ¶
Index - Attempt to find and return an object within a JSON array by index.
func (*Container) Object ¶
Object - Create a new JSON object at a path. Returns an error if the path contains a collision with a non object type.
func (*Container) ObjectI ¶
ObjectI - Create a new JSON object at an array index. Returns an error if the object is not an array or the index is out of bounds.
func (*Container) Search ¶
Search - Attempt to find and return an object within the JSON structure by specifying the hierarchy of field names to locate the target. If the search encounters an array and has not reached the end target then it will iterate each object of the array for the target and return all of the results in a JSON array.
func (*Container) Set ¶
Set - Set the value of a field at a JSON path, any parts of the path that do not exist will be constructed, and if a collision occurs with a non object type whilst iterating the path an error is returned.