Documentation ¶
Index ¶
- Variables
- func Marshal(obj interface{}) ([]byte, error)
- func MarshalHelper(obj interface{}, escapeHtml bool, indent bool) ([]byte, error)
- func MarshalToFile(obj interface{}, path string) error
- func MarshalToFileOptions(obj interface{}, path string, options *MarshalOptions) error
- func MarshalToString(obj interface{}) (string, error)
- func MarshalWithOptions(obj interface{}, options *MarshalOptions) ([]byte, error)
- func MustMarshalToString(obj interface{}) string
- func Parse[T any](bs []byte) (*T, error)
- func ParseFile[T any](path string) (*T, error)
- func ParseString[T any](contents string) (*T, error)
- func Print(obj interface{})
- func PrintOptions(obj interface{}, options *MarshalOptions)
- func Remarshal(obj interface{}) (interface{}, error)
- func SortFileOptions(path string, escapeHtml bool, indent bool) error
- func SortOptions(contents []byte, escapeHtml bool, indent bool) ([]byte, error)
- type MarshalOptions
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultMarshalOptions = &MarshalOptions{EscapeHTML: true, Indent: true, Sort: false}
Functions ¶
func MarshalHelper ¶
func MarshalToFile ¶
func MarshalToFileOptions ¶
func MarshalToFileOptions(obj interface{}, path string, options *MarshalOptions) error
func MarshalToString ¶
func MarshalWithOptions ¶
func MarshalWithOptions(obj interface{}, options *MarshalOptions) ([]byte, error)
func MustMarshalToString ¶ added in v0.2.0
func MustMarshalToString(obj interface{}) string
func ParseString ¶ added in v0.1.9
func PrintOptions ¶
func PrintOptions(obj interface{}, options *MarshalOptions)
func Remarshal ¶
func Remarshal(obj interface{}) (interface{}, error)
Remarshal is of questionable utility. It first marshals, then unmarshals
into an `interface{}`, which throws away struct types (struct types cause problems for predictability of order during marshaling).
func SortOptions ¶
SortOptions is used to get keys from a struct into a sorted order.
See https://stackoverflow.com/a/61887446/894284. Apparently, golang's json library sorts keys from maps, but NOT from structs. So this function works by reading json into a generic structure of maps, then marshaling back into completely sorted json. NOTE: this only works for a json object.
Types ¶
type MarshalOptions ¶
Click to show internal directories.
Click to hide internal directories.