Documentation ¶
Overview ¶
Package json provides manipulation of JSON data.
Index ¶
- type Data
- func (j *Data) Append(path string, value *Data) bool
- func (j *Data) AppendArray(path string) bool
- func (j *Data) AppendBool(path string, value bool) bool
- func (j *Data) AppendFloat64(path string, value float64) bool
- func (j *Data) AppendInt64(path string, value int64) bool
- func (j *Data) AppendMap(path string) bool
- func (j *Data) AppendStr(path, value string) bool
- func (j *Data) Bool(path string) bool
- func (j *Data) BoolRelaxed(path string) bool
- func (j *Data) Bytes() []byte
- func (j *Data) Delete(path string) bool
- func (j *Data) Exists(path string) bool
- func (j *Data) Float64(path string) float64
- func (j *Data) Float64Relaxed(path string) float64
- func (j *Data) Index(index int) *Data
- func (j *Data) Int64(path string) int64
- func (j *Data) Int64Relaxed(path string) int64
- func (j *Data) IsArray() bool
- func (j *Data) IsMap() bool
- func (j *Data) Keys() []string
- func (j *Data) NewArray(path string) bool
- func (j *Data) NewMap(path string) bool
- func (j *Data) Path(path string) *Data
- func (j *Data) PostRequest(url string) (statusCode int, body *Data, err error)
- func (j *Data) Raw() interface{}
- func (j *Data) Set(path string, value *Data) bool
- func (j *Data) SetBool(path string, value bool) bool
- func (j *Data) SetFloat64(path string, value float64) bool
- func (j *Data) SetInt64(path string, value int64) bool
- func (j *Data) SetStr(path, value string) bool
- func (j *Data) Size() int
- func (j *Data) Str(path string) string
- func (j *Data) String() string
- func (j *Data) Unmarshal(path string, value interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct {
// contains filtered or unexported fields
}
Data provides conveniences for working with JSON data.
func GetRequest ¶
GetRequest calls http.Get with the URL and returns the response body as a new Data object.
func MustParseStream ¶
MustParseStream is the same as calling ParseStream, but without the error code on return.
func Parse ¶
Parse JSON data from bytes. If the data can't be loaded, a valid, empty Data will still be returned, along with an error.
func ParseStream ¶
ParseStream parses JSON data from the stream. If the data can't be loaded, a valid, empty Data will still be returned, along with an error.
func (*Data) Append ¶
Append a Data value to an array at the specified path. The array must already exist. Returns true if successful.
func (*Data) AppendArray ¶
AppendArray appends a new array to an array at the specified path. The array must already exist. Returns true if successful.
func (*Data) AppendBool ¶
AppendBool appends a bool to an array at the specified path. The array must already exist. Returns true if successful.
func (*Data) AppendFloat64 ¶
AppendFloat64 appends a float64 to an array at the specified path. The array must already exist. Returns true if successful.
func (*Data) AppendInt64 ¶
AppendInt64 appends an int64 to an array at the specified path. The array must already exist. Returns true if successful.
func (*Data) AppendMap ¶
AppendMap appends a new map to an array at the specified path. The array must already exist. Returns true if successful.
func (*Data) AppendStr ¶
AppendStr appends a string to an array at the specified path. The array must already exist. Returns true if successful.
func (*Data) Bool ¶
Bool extracts a bool from the path. Returns false if the path isn't present or isn't a boolean type.
func (*Data) BoolRelaxed ¶
BoolRelaxed extracts a bool from the path. Returns false if the path isn't present or can't be converted to a boolean type.
func (*Data) Float64 ¶
Float64 extracts an float64 from the path. Returns 0 if the path isn't present or isn't a numeric type.
func (*Data) Float64Relaxed ¶
Float64Relaxed extracts an float64 from the path. Returns 0 if the path isn't present or can't be converted to a numeric type.
func (*Data) Index ¶
Index returns the object at the specified index within an array, or nil if this isn't an array or the index isn't valid.
func (*Data) Int64 ¶
Int64 extracts an int64 from the path. Returns 0 if the path isn't present or isn't a numeric type.
func (*Data) Int64Relaxed ¶
Int64Relaxed extracts an int64 from the path. Returns 0 if the path isn't present or can't be converted to a numeric type.
func (*Data) NewArray ¶
NewArray creates an array at the specified path. Any parts of the path that do not exist will be created. Returns true if successful, or false if a collision occurs with a non-object type while traversing the path.
func (*Data) NewMap ¶
NewMap creates a map at the specified path. Any parts of the path that do not exist will be created. Returns true if successful, or false if a collision occurs with a non-object type while traversing the path.
func (*Data) Path ¶
Path searches the dot-separated path and returns the object at that point. If the search encounters an array and has not reached the end target, then it will iterate through the array for the target and return all results in a Data array.
func (*Data) PostRequest ¶
PostRequest calls http.Post with the URL and the contents of this Data object and returns the response body as a new Data object.
func (*Data) Set ¶
Set a Data value at the specified path. Any parts of the path that do not exist will be created. Returns true if successful, or false if a collision occurs with a non-object type while traversing the path.
func (*Data) SetBool ¶
SetBool a bool at the specified path. Any parts of the path that do not exist will be created. Returns true if successful, or false if a collision occurs with a non-object type while traversing the path.
func (*Data) SetFloat64 ¶
SetFloat64 a float64 at the specified path. Any parts of the path that do not exist will be created. Returns true if successful, or false if a collision occurs with a non-object type while traversing the path.
func (*Data) SetInt64 ¶
SetInt64 an int64 at the specified path. Any parts of the path that do not exist will be created. Returns true if successful, or false if a collision occurs with a non-object type while traversing the path.
func (*Data) SetStr ¶
SetStr a string at the specified path. Any parts of the path that do not exist will be created. Returns true if successful, or false if a collision occurs with a non-object type while traversing the path.
func (*Data) Size ¶
Size returns the number of elements in an array or map, or 0 if this is neither type.