author | Mikael Berthe <mikael@lilotux.net> |
Tue, 23 Aug 2022 22:39:43 +0200 | |
changeset 260 | 445e01aede7e |
permissions | -rw-r--r-- |
260 | 1 |
package json |
2 |
||
3 |
import ( |
|
4 |
"encoding/json" |
|
5 |
) |
|
6 |
||
7 |
// Codec implements the encoding.Encoder and encoding.Decoder interfaces for JSON encoding. |
|
8 |
type Codec struct{} |
|
9 |
||
10 |
func (Codec) Encode(v map[string]interface{}) ([]byte, error) { |
|
11 |
// TODO: expose prefix and indent in the Codec as setting? |
|
12 |
return json.MarshalIndent(v, "", " ") |
|
13 |
} |
|
14 |
||
15 |
func (Codec) Decode(b []byte, v map[string]interface{}) error { |
|
16 |
return json.Unmarshal(b, &v) |
|
17 |
} |