Skip to content
Node: JSON.parse/stringifygithub.com/sahilkhaire/gox/json

ParseFile

Overview

ParseFile reads path and unmarshals into v.

Part of the json package — Node.js analog: JSON.parse/stringify.

Signature

go
func ParseFile(ctx context.Context, path string, v any) error

Compare: Node.js · Standard Go · gox

js
JSON.parse(fs.readFileSync('cfg.json','utf8'));
go
b, err := os.ReadFile(path)
err = json.Unmarshal(b, &cfg)
go
import "github.com/sahilkhaire/gox/json"

dir := t.TempDir()
path := filepath.Join(dir, "data.json")
var m map[string]int

Example

go
import "github.com/sahilkhaire/gox/json"

dir := t.TempDir()
path := filepath.Join(dir, "data.json")
var m map[string]int

Tips

Import github.com/sahilkhaire/gox/json and call ParseFile directly. See the comparison below for the standard library equivalent.

Standard library alternative

Use the standard library directly:

go
b, err := os.ReadFile(path)
err = json.Unmarshal(b, &cfg)

Back to json package overview

MIT Licensed · Built for Node.js developers moving to Go