Documentation
¶
Index ¶
- Constants
- Variables
- type Field
- type JSONObject
- func (o *JSONObject) ConvertSlice(slice any) (s []any)
- func (o *JSONObject) FromStruct(s any)
- func (o *JSONObject) GetField(name string) any
- func (o *JSONObject) HasField(name string) bool
- func (o *JSONObject) IsEmpty() bool
- func (o JSONObject) MarshalJSON() (out []byte, err error)
- func (o *JSONObject) SetField(name string, value any)
- type NameConv
- type Options
Constants ¶
const ( CamelCase = NameConv(iota) SnakeCase LowerCase UpperCase )
Variables ¶
var (
ErrUnkNameConv = fmt.Errorf("unknown name convention")
)
Functions ¶
This section is empty.
Types ¶
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 (*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