-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakejson.go
30 lines (28 loc) · 892 Bytes
/
makejson.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
/*
Problem statement
Write a program which prompts the user to first enter a name, and then enter an address. Your program should create a map and add the name
and address to the map using the keys “name” and “address”, respectively. Your program should use Marshal() to create a JSON object from the map,
and then your program should print the JSON object.
*/
/*func main() {
fmt.Println("Enter a name")
scanner := bufio.NewScanner(os.Stdin)
user := make(map[string]string)
if scanner.Scan(){
fmt.Println("Enter your name.")
name := scanner.Text()
user["name"] = name
}
if scanner.Scan(){
fmt.Println("Enter your address.")
address := scanner.Text()
user["address"] = address
}
obj,err := json.Marshal(user)
if err != nil{
log.Fatal("error in json to byte serialization. err is ",err)
return
}
fmt.Println("json object is ",string(obj))
}*/