jsonutil

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2023 License: UPL-1.0 Imports: 2 Imported by: 0

Documentation

Overview

Package jsonutil provides utility functions for manipulating JSON.

Index

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

func ExpectObject(data interface{}) (map[string]interface{}, error)

ExpectObject checks if the specified data represents a JSON object, that is a Go value of type map[string]interface{}.

func ExpectString

func ExpectString(data interface{}) (string, error)

ExpectString checks if the specified data represents a JSON string, that is a Go value of type string.

func GetArrayFromObject

func GetArrayFromObject(m map[string]interface{}, field string) (a []interface{}, ok bool)

GetArrayFromObject retrieves an array value associated with the specified top-level field from a JSON object.

func GetNumberFromObject

func GetNumberFromObject(m map[string]interface{}, field string) (f float64, ok bool)

GetNumberFromObject retrieves the float64 value associated with the specified top-level field from a JSON object.

func GetStringFromObject

func GetStringFromObject(m map[string]interface{}, field string) (s string, ok bool)

GetStringFromObject retrieves the string value associated with the specified top-level field from a JSON object.

func ToObject

func ToObject(jsonStr string) (v map[string]interface{}, err error)

ToObject decodes the jsonStr as a JSON object.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL