Documentation ¶
Overview ¶
Package json implements helper functions to interact with json
Index ¶
- func GetNestedValue(inputMap map[string]interface{}, keys ...string) interface{}
- type EmptyPolicy
- type RawObjectWriter
- func (writer *RawObjectWriter) AddInt64Field(fieldName string, value int64)
- func (writer *RawObjectWriter) AddStringField(fieldName string, value string, policy EmptyPolicy)
- func (writer *RawObjectWriter) AddStringValue(value string)
- func (writer *RawObjectWriter) FinishArrayField() error
- func (writer *RawObjectWriter) FinishObject() error
- func (writer *RawObjectWriter) Flush() error
- func (writer *RawObjectWriter) StartArrayField(fieldName string) error
- func (writer *RawObjectWriter) StartObject() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetNestedValue ¶
GetNestedValue returns the value in the map specified by the array keys, where each value is another depth level in the map. Returns nil if the map doesn't contain the nested key.
Types ¶
type EmptyPolicy ¶
type EmptyPolicy int
EmptyPolicy defines the behavior when adding an empty string
const ( // OmitEmpty does not write the field if the string is empty OmitEmpty EmptyPolicy = iota // AllowEmpty writes the string even if the string is empty AllowEmpty )
type RawObjectWriter ¶
type RawObjectWriter struct {
// contains filtered or unexported fields
}
RawObjectWriter contains helper functions to write JSON using the raw API.
func NewRawObjectWriter ¶
func NewRawObjectWriter(stream *jsoniter.Stream) *RawObjectWriter
NewRawObjectWriter creates a new instance of RawObjectWriter
func (*RawObjectWriter) AddInt64Field ¶
func (writer *RawObjectWriter) AddInt64Field(fieldName string, value int64)
AddInt64Field adds a new field of type int64
func (*RawObjectWriter) AddStringField ¶
func (writer *RawObjectWriter) AddStringField(fieldName string, value string, policy EmptyPolicy)
AddStringField adds a new field of type string
func (*RawObjectWriter) AddStringValue ¶
func (writer *RawObjectWriter) AddStringValue(value string)
AddStringValue adds a string (for example inside an array)
func (*RawObjectWriter) FinishArrayField ¶
func (writer *RawObjectWriter) FinishArrayField() error
FinishArrayField finishes an array field
func (*RawObjectWriter) FinishObject ¶
func (writer *RawObjectWriter) FinishObject() error
FinishObject finishes a JSON object (add '}')
func (*RawObjectWriter) StartArrayField ¶
func (writer *RawObjectWriter) StartArrayField(fieldName string) error
StartArrayField starts a new field of type array
func (*RawObjectWriter) StartObject ¶
func (writer *RawObjectWriter) StartObject() error
StartObject starts a new JSON object (add '{')