Documentation ¶
Overview ¶
json-lossless populates structs from JSON and allows serialization back to JSON without losing fields that are not explicitly defined in the struct.
Source code: https://github.com/joeshaw/json-lossless
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JSON ¶
type JSON struct {
// contains filtered or unexported fields
}
The JSON type contains the state of the decoded data. Embed this type in your type and implement MarshalJSON and UnmarshalJSON methods to add lossless encoding and decoding.
Example:
type Person struct { lossless.JSON `json:"-"` Name string Age int Address string } func (p *Person) UnmarshalJSON(data []byte) error { return p.JSON.UnmarshalJSON(p, data) } func (p Person) MarshalJSON() ([]byte, error) { return p.JSON.MarshalJSON(p) }
func (*JSON) MarshalJSON ¶
Marshals the given source into JSON data. Users should call this from their type's MarshalJSON method.
Example:
func (p Person) MarshalJSON() ([]byte, error) { return p.JSON.MarshalJSON(p) }
func (*JSON) Set ¶
Sets a JSON value not represented in the struct type. The argument list is a set of strings referring to the JSON path, with the value to be set as the last value.
Example:
// This sets {"Phone": {"Mobile": "614-555-1212"}} in the JSON p.Set("Phone", "Mobile", "614-555-1212")
func (*JSON) UnmarshalJSON ¶
Unmarshals JSON data into the given destination. Users should call this from their type's UnmarshalJSON method.
Example:
func (p *Person) UnmarshalJSON(data []byte) error { return p.JSON.UnmarshalJSON(p, data) }