jsonobj

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

README

jsonobj

JSON object crafting and manipulation without having to define structure or map

GitHub Workflow Status (with event) Coverage GitHub tag (with filter)

Documentation

Index

Constants

View Source
const (
	CamelCase = NameConv(iota)
	SnakeCase
	LowerCase
	UpperCase
)

Variables

View Source
var (
	ErrUnkNameConv = fmt.Errorf("unknown name convention")
)

Functions

This section is empty.

Types

type Field

type Field struct {
	Name  string
	Value any
}

Field structure definition

type JSONObject

type JSONObject struct {
	Options *Options
	// contains filtered or unexported fields
}

JSONObject structure definition

func FromMap

func FromMap(m map[string]any) (o *JSONObject)

FromMap creates a new JSONObject from a map

func FromStruct

func FromStruct(s any) (o *JSONObject)

FromMap creates a new JSONObject from a structure

func FromStructWithOptions

func FromStructWithOptions(s any, opt Options) (o *JSONObject)

FromMap creates a new JSONObject with options from a structure

func New

func New() *JSONObject

New creates an empty new JSONObject

func (*JSONObject) ConvertSlice

func (o *JSONObject) ConvertSlice(slice any) (s []any)

ConvertSlice converts any slice to a JSONObject ready slice. It is useful to recursively convert slice of structures, so that options are also applied to slice elements. On slices containing base types, this method has no effect.

func (*JSONObject) FromStruct added in v1.0.1

func (o *JSONObject) FromStruct(s any)

FromStruct modifies JSONObject from structure

func (*JSONObject) GetField

func (o *JSONObject) GetField(name string) any

GetField returns field's value if any. It panics if field is not present

func (*JSONObject) HasField

func (o *JSONObject) HasField(name string) bool

HasField returns true if field is present in JSONObject

func (*JSONObject) IsEmpty

func (o *JSONObject) IsEmpty() bool

IsEmpty checks wether the JSONObject is empty

func (JSONObject) MarshalJSON

func (o JSONObject) MarshalJSON() (out []byte, err error)

json marshaling implementation

func (*JSONObject) SetField

func (o *JSONObject) SetField(name string, value any)

SetField sets a field of the object. If the field is already existing, value is replaced

type NameConv

type NameConv int

NameConv defines a custom type for identifying naming convention

type Options

type Options struct {
	FieldNameConvention NameConv
}

Options to apply modification on JSONObject fields

Jump to

Keyboard shortcuts

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