Documentation ¶
Overview ¶
Package jsonutil provides utility functions for manipulating JSON.
Index ¶
- func AsJSON(v interface{}) string
- func AsPrettyJSON(v interface{}) string
- func ExpectObject(data interface{}) (map[string]interface{}, error)
- func ExpectString(data interface{}) (string, error)
- func GetArrayFromObject(m map[string]interface{}, field string) (a []interface{}, ok bool)
- func GetNumberFromObject(m map[string]interface{}, field string) (f float64, ok bool)
- func GetStringFromObject(m map[string]interface{}, field string) (s string, ok bool)
- func ToObject(jsonStr string) (v map[string]interface{}, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsJSON ¶
func AsJSON(v interface{}) string
AsJSON encodes the specified value into a JSON string.
func AsPrettyJSON ¶
func AsPrettyJSON(v interface{}) string
AsPrettyJSON encodes the specified value into a JSON string, adding appropriate indents in the returned string.
func ExpectObject ¶
ExpectObject checks if the specified data represents a JSON object, that is a Go value of type map[string]interface{}.
func ExpectString ¶
ExpectString checks if the specified data represents a JSON string, that is a Go value of type string.
func GetArrayFromObject ¶
GetArrayFromObject retrieves an array value associated with the specified top-level field from a JSON object.
func GetNumberFromObject ¶
GetNumberFromObject retrieves the float64 value associated with the specified top-level field from a JSON object.
func GetStringFromObject ¶
GetStringFromObject retrieves the string value associated with the specified top-level field from a JSON object.
Types ¶
This section is empty.