Documentation
¶
Overview ¶
Package gson provides searching for json strings and setting json values
Index ¶
- func PrettyPrint(v any)
- type Gson
- func (gson *Gson) Delete(path string) (json *Gson, err error)
- func (gson *Gson) GetGson(path string) *Gson
- func (gson *Gson) MarshalJSON() ([]byte, error)
- func (gson *Gson) Print()
- func (gson *Gson) Set(path string, value interface{}) (json *Gson, err error)
- func (gson *Gson) SetRaw(path, value string) (json *Gson, err error)
- func (gson *Gson) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrettyPrint ¶ added in v0.2.3
func PrettyPrint(v any)
PrettyPrint print any struct or raw json string
Types ¶
type Gson ¶
Gson Inherits from gjson.Result
Note that when using the Get method, the returned result is gjson.Result instead of Gson
You may need to use the Gson.GetGson method
func Parse ¶
Parse parses the json and returns a result.
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. If you are consuming JSON from an unpredictable source then you may want to use the Valid function first.
func ParseBytes ¶
ParseBytes parses the json and returns a result. If working with bytes, this method preferred over Parse(string(data))
func (*Gson) GetGson ¶ added in v0.1.1
GetGson searches result for the specified path. The result should be a JSON array or object.
func (*Gson) MarshalJSON ¶
MarshalJSON Serialize gson to byte slice
func (*Gson) Set ¶
Set sets a json value for the specified path. A path is in dot syntax, such as "name.last" or "age". A value should be a simple JSON value and not a JSON string. 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 (*Gson) 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 (*Gson) UnmarshalJSON ¶
UnmarshalJSON Deserialize data to gson