blob: 715e96d61cb6a642c5be5c97e925378a64e0f8b4 [file] [log] [blame]
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package database
import (
"encoding/json"
"os"
"golang.org/x/vulndb/internal/derrors"
)
func WriteJSON(filename string, value any, indent bool) (err error) {
defer derrors.Wrap(&err, "writeJSON(%s)", filename)
j, err := jsonMarshal(value, indent)
if err != nil {
return err
}
return os.WriteFile(filename, j, 0644)
}
func jsonMarshal(v any, indent bool) ([]byte, error) {
if indent {
return json.MarshalIndent(v, "", " ")
}
return json.Marshal(v)
}