Answers for "golang parse json file"

Go
0

golang parse json file

package main

import (
	"encoding/json"
	"fmt"
	"os"
)

type Account struct {
	Username string
	Email    string
	Password string
}

func main() {

	file, _ := os.Open("account.json")
	defer file.Close()

	decode := json.NewDecoder(file)
	account := Account{}
	err := decode.Decode(&account)

	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(account)
}
Posted by: Guest on March-18-2021

Browse Popular Code Answers by Language