3
votes

I want to convert byte array to map[string,string] using golang. I tried this:

var byte := json.Marshal(input)
var map := make(map[string]string *byte) // NOT WORKING

if byte holds value like {\"hello\":\"world\",...} How to create the map from byte array

Please help.

1
The code you posted makes not much sense (it has multiple compilation errors). Please explain in greater detail what you want (edit the question). - icza
What is a map[string]string *byte supposed to be? Your syntax has too many errors to try and guess. - JimB
Please take a look at: blog.golang.org/json-and-go to further understand how to do what you want - Alexander W
There's no such thing as map[string,string]. - khrm

1 Answers

15
votes

You probably want to do something like

m := make(map[string]string)
err := json.Unmarshal(input, &m)

This creates a new map[string]string and unmarshals a byte array into it.