package jsonutil

import (
	"bytes"
	"encoding/json"
	"strings"
)

func Encode(v interface{}) (string, error) {
	var buf bytes.Buffer
    err := json.NewEncoder(&buf).Encode(v)
    if err != nil {
        return "", err
    }
	return strings.TrimRight(buf.String(), "\n"), nil
}

func Decode(s string) (v interface{}, err error) {
	err = json.NewDecoder(bytes.NewReader([]byte(s))).Decode(&v)
	return
}

package jsonutil

import (
	"encoding/json"
)

func Encode(v interface{}) (string, error) {
    bytes, err := json.Marshal(v)
    if err != nil {
        return "", err
    }
	return string(bytes), nil
}

func Decode(s string) (v interface{}, err error) {
	err = json.Unmarshal([]byte(s), &v)
	return
}

Use Marshal and Unmarshal instead of Encode and Decode.
Use Marshal and Unmarshal instead of Encode and Decode.
