Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

golang parse json file

// You need a struct to unmarshal file:
// After running this function with Some_struct, 
// your object will be filled with json file data
func parseJsonFile(file string, obj *Some_struct) {
	jsonFile, err := os.Open(file)
	// if we os.Open returns an error then handle it
	if err != nil {
		fmt.Println(err, "| Can find a file")
	} else {
		fmt.Println("File found!")
	}

	// defer the closing of our jsonFile so that we can parse it later on
	defer jsonFile.Close()

	// read our opened xmlFile as a byte array.
	byteValue, _ := ioutil.ReadAll(jsonFile)

	// we unmarshal our byteArray which contains our
	// jsonFile's content into 'users' which we defined above
	json.Unmarshal(byteValue, &obj)
}
Source by www.sohamkamani.com #
 
PREVIOUS NEXT
Tagged: #golang #parse #json #file
ADD COMMENT
Topic
Name
8+3 =