json

package
v0.0.0-...-8b058bf Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StructToJson

func StructToJson(input any, options ...Option) string

A convenience function for printing an arbitrary struct as a JSON blob with/without indent, prefix, and dynamically ignored keys. Particularly useful when dealing with user-generated or otherwise dynamic/unpredictable structures.

Types

type Option

type Option func(settings *Settings)

Options are functions you can pass to StructToJson to apply the settings dynamically

func WithIgnore

func WithIgnore(dotpaths ...string) Option

Adds one or more dotpaths (or top-level keys) to be ignored when calling StructToJson

func WithIndent

func WithIndent(indent string) Option

Sets the Indent string when calling StructToJson

func WithPrefix

func WithPrefix(prefix string) Option

Sets the Prefix string when calling StructToJson

type Settings

type Settings struct {
	// If specified, prefixes each line after the first with the value
	Prefix string
	// If specified, the JSON will be rendered indented, repeating this value once for each level of indent
	Indent string
	// A list of fields to ignore. You can specify dotpath notation, like "foo.bar"
	Ignore []string
}

Configuration for how a given object should be converted to JSON

Jump to

Keyboard shortcuts

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