func Save(ks *JSONStore, filename string) (err error) {
	ks.RLock()
	defer ks.RUnlock()
	toSave := make(map[string]string)
	for key := range ks.Data {
		toSave[key] = string(ks.Data[key])
	}
	f, err := os.Create(filename)
	if err != nil {
		return err
	}
	defer f.Close()
	if strings.HasSuffix(filename, ".gz") {
		w := gzip.NewWriter(f)
		defer w.Close()
		enc := json.NewEncoder(w)
		enc.SetIndent("", " ")
		return enc.Encode(toSave)
	}
	enc := json.NewEncoder(f)
	enc.SetIndent("", " ")
	return enc.Encode(toSave)
}
Save writes the jsonstore to disk
package jsonstore
import (
	"compress/gzip"
	"encoding/json"
	"io"
	"os"
	"regexp"
	"strings"
	"sync"
)
type NoSuchKeyError struct {
	key string
}
func (err NoSuchKeyError) Error() string {
	return "jsonstore: no such key \"" + err.key + "\""
}
type JSONStore struct {
	Data map[string]json.RawMessage
	sync.RWMutex
}
func Open(filename string) (*JSONStore, error) {
	var err error
	f, err := os.Open(filename)
	defer f.Close()
	if err != nil {
		return nil, err
	}
	var w io.Reader
	if strings.HasSuffix(filename, ".gz") {
		w, err = gzip.NewReader(f)
		if err != nil {
			return nil, err
		}
	} else {
		w = f
	}
	toOpen := make(map[string]string)
	err = json.NewDecoder(w).Decode(&toOpen)
	if err != nil {
		return nil, err
	}
	ks := new(JSONStore)
	ks.Data = make(map[string]json.RawMessage)
	for key := range toOpen {
		ks.Data[key] = json.RawMessage(toOpen[key])
	}
	return ks, nil
}