Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OrderedMap ¶
type OrderedMap struct {
// contains filtered or unexported fields
}
An OrderedMap keeps track of the order keys are placed in it
Rather than be recursive, the values are of type json.RawMessage and thus can be decoded separately
func (*OrderedMap) Get ¶
func (o *OrderedMap) Get(k string) json.RawMessage
Get returns the json value associated with a key
Example ¶
jsonData := `{ "z": 1, "a": 2 }` m := NewOrderedMap() err := json.Unmarshal([]byte(jsonData), &m) if err != nil { fmt.Println("error:", err) } var val int err = json.Unmarshal(m.Get("z"), &val) if err != nil { fmt.Println("error:", err) } fmt.Println(val)
Output: 1
func (*OrderedMap) MarshalJSON ¶
func (o *OrderedMap) MarshalJSON() ([]byte, error)
func (*OrderedMap) Set ¶
func (o *OrderedMap) Set(k string, v json.RawMessage)
Set sets the value of a key
If the key already exists in the map it will retain its position otherwise it will be placed at the end
Example ¶
jsonData := `{ "z": 1, "a": 2 }` m := NewOrderedMap() err := json.Unmarshal([]byte(jsonData), &m) if err != nil { fmt.Println("error:", err) } newVal := 3 newData, err := json.Marshal(&newVal) if err != nil { fmt.Println("error:", err) } m.Set("z", newData) data, err := json.Marshal(&m) if err != nil { fmt.Println("error:", err) } fmt.Println(string(data))
Output: {"z":3,"a":2}
func (*OrderedMap) UnmarshalJSON ¶
func (o *OrderedMap) UnmarshalJSON(b []byte) error
Click to show internal directories.
Click to hide internal directories.