Documentation ¶
Overview ¶
Package sjson provides setting json values.
Index ¶
- func Delete(json, path string) (string, error)
- func DeleteBytes(json []byte, path string) ([]byte, error)
- func Set(json, path string, value interface{}) (string, error)
- func SetBytes(json []byte, path string, value interface{}) ([]byte, error)
- func SetBytesOptions(json []byte, path string, value interface{}, opts *Options) ([]byte, error)
- func SetOptions(json, path string, value interface{}, opts *Options) (string, error)
- func SetRaw(json, path, value string) (string, error)
- func SetRawBytes(json []byte, path string, value []byte) ([]byte, error)
- func SetRawBytesOptions(json []byte, path string, value []byte, opts *Options) ([]byte, error)
- func SetRawOptions(json, path, value string, opts *Options) (string, error)
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteBytes ¶
DeleteBytes deletes a value from json for the specified path.
func Set ¶
Set sets a json value for the specified path. A path is in dot syntax, such as "name.last" or "age". This function expects that the json is well-formed, and does not validate. Invalid json will not panic, but it may return back unexpected results. An error is returned if the path is not valid.
A path is a series of keys separated by a dot.
{ "name": {"first": "Tom", "last": "Anderson"}, "age":37, "children": ["Sara","Alex","Jack"], "friends": [ {"first": "James", "last": "Murphy"}, {"first": "Roger", "last": "Craig"} ] } "name.last" >> "Anderson" "age" >> 37 "children.1" >> "Alex"
func SetBytes ¶
SetBytes sets a json value for the specified path. If working with bytes, this method preferred over Set(string(data), path, value)
func SetBytesOptions ¶
SetBytesOptions sets a json value for the specified path with options. If working with bytes, this method preferred over SetOptions(string(data), path, value)
func SetOptions ¶
SetOptions sets a json value for the specified path with options. A path is in dot syntax, such as "name.last" or "age". This function expects that the json is well-formed, and does not validate. Invalid json will not panic, but it may return back unexpected results. An error is returned if the path is not valid.
func SetRaw ¶
SetRaw sets a raw json value for the specified path. This function works the same as Set except that the value is set as a raw block of json. This allows for setting premarshalled json objects.
func SetRawBytes ¶
SetRawBytes sets a raw json value for the specified path. If working with bytes, this method preferred over SetRaw(string(data), path, value)
func SetRawBytesOptions ¶
SetRawBytesOptions sets a raw json value for the specified path with options. If working with bytes, this method preferred over SetRawOptions(string(data), path, value, opts)
func SetRawOptions ¶
SetRawOptions sets a raw json value for the specified path with options. This furnction works the same as SetOptions except that the value is set as a raw block of json. This allows for setting premarshalled json objects.
Types ¶
type Options ¶
type Options struct { // Optimistic is a hint that the value likely exists which // allows for the sjson to perform a fast-track search and replace. Optimistic bool // ReplaceInPlace is a hint to replace the input json rather than // allocate a new json byte slice. When this field is specified // the input json will not longer be valid and it should not be used // In the case when the destination slice doesn't have enough free // bytes to replace the data in place, a new bytes slice will be // created under the hood. // The Optimistic flag must be set to true and the input must be a // byte slice in order to use this field. ReplaceInPlace bool }
Options represents additional options for the Set and Delete functions.