Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
func Decode(data []byte, val Unmarshaller, cfgs ...Config) error
Decode takes a JSON string in a byte array and reads the content of the JSON into an object in the parameter list that implements the Unmarshaller interface. An optional list of config options can be provided to modify the decoder.
func Unmarshal ¶
Unmarshal takes a JSON string in a byte array and reads the content of the JSON into an object in the parameter list. The object must implement the Unmarshaller interface, otherwise it returns an error. This function matches the signature of the standard library's Unmarshal function. To enforce objects implementing the Unmarshaller interface at compile time, use the Decode function instead.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config describes optional settings that alter the behavior of the encoder/decoder.
func MergeConfigs ¶
MergeConfigs takes multiple config options and merges them into a single object.
func UseFilter ¶
UseFilter creates a config from a filter list. Only fields that appear in the filter list will be processed by the encoder/decoder If the filter is nil, all elements get processed.
Example:
var filter = []parsley.Filter{ {"name": []parsley.Filter{ {"firstName": nil}, {"lastName": nil}, }}, {"address": []parsley.Filter{ {"country": nil}, {"city": nil}, }}, {"age": nil}, }
func UseFixedBuffer ¶
UseFixedBuffer creates a config to add extra buffer space for the encoder. The function adds a fixed number of bytes space.
A larger buffer can speed up encoding by reducing required allocations. Extra buffer space is only recommended if the object contains strings with characters that should be escaped.
func UseRelativeBuffer ¶
UseRelativeBuffer creates a config to add extra buffer space for the encoder. The function calculates the length of all string fields and uses a percentage of that as extra buffer space.
A larger buffer can speed up encoding by reducing required allocations. Extra buffer space is only recommended if the object contains strings with characters that should be escaped.
Directories ¶
Path | Synopsis |
---|---|
tests
|
|
basics
Code generated by parsley for scanning JSON strings.
|
Code generated by parsley for scanning JSON strings. |
controls
Code generated by parsley for scanning JSON strings.
|
Code generated by parsley for scanning JSON strings. |
externals
Code generated by parsley for scanning JSON strings.
|
Code generated by parsley for scanning JSON strings. |
models
Code generated by parsley for scanning JSON strings.
|
Code generated by parsley for scanning JSON strings. |