Skip to content

Instantly share code, notes, and snippets.

@ekanna
Created July 17, 2013 17:02
Show Gist options
  • Save ekanna/6022426 to your computer and use it in GitHub Desktop.
Save ekanna/6022426 to your computer and use it in GitHub Desktop.
Generating arbitrary JSON data using map in golang
// Generating arbitrary JSON data using map
package main
import "fmt"
import "encoding/json"
func main() {
keys := []string{"Segment", "Jan", "Feb", "Apr"}
values := []interface{}{"ME",1000,2000,3000}
fmt.Println(keys)
fmt.Println(values)
// map values to keys
m := make(map[string]interface{})
for i,v := range values {
m[keys[i]] = v
}
fmt.Println(m)
// convert map to JSON
data, _ := json.Marshal(m)
fmt.Printf("%s", data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment