I've got a small json file
{
"first": "",
"second": ""
}
and I want to ocasionally modify its values.
I managed to open the file using Unmarshal but I don't know how to change its values.
package main
import (
"encoding/json"
"io/ioutil"
)
type Data struct {
First string `json:"first"`
Second string `json:"second"`
}
func main() {
//read json file with io/ioutil
file, _ := ioutil.ReadFile("temp.json")
var data Data
json.Unmarshal(file, &data)
}
I saw that you can Marshal and it should change the json file by the Data struct but I don't want to rewrite the file everytime just to modify a single value. Is there a way to change by variable or I do have to use the Marshal function?