Skip to content

Instantly share code, notes, and snippets.

@nevzatalkan
Last active November 14, 2022 21:04
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save nevzatalkan/f5c5ef66e88dd446976401967b6731e8 to your computer and use it in GitHub Desktop.
Save nevzatalkan/f5c5ef66e88dd446976401967b6731e8 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
)
func main() {
b := []byte(`{"key":"value"}`)
var f interface{}
json.Unmarshal(b, &f)
myMap := f.(map[string]interface{})
fmt.Println(myMap["key"])
}
@adpande
Copy link

adpande commented May 9, 2020

Thanks man! You saved my day

@pagondel
Copy link

pagondel commented Sep 2, 2020

thanks!

@chibelsonda
Copy link

Thank you very much.

@harsh244
Copy link

harsh244 commented Oct 7, 2020

can we not do f.(map[string]string) directly if we know the values are also string?

@thaison247
Copy link

Thanks!

@vishutrilio
Copy link

Thank you so much

@joechen1105
Copy link

THANK YOU!!!

@aldlfkahs
Copy link

You saved my life

@bharathraj-e
Copy link

Simple and saving lives

@satyamkb
Copy link

Life saver

@brunotrajano-mm
Copy link

Thanks! It helped a lot

@ashmilhussain
Copy link

how to do this for a nested data

b := []byte({"key":{"key1":"value"}})

@vmpastran
Copy link

Merci beaucoup

@sramac2
Copy link

sramac2 commented Feb 17, 2022

Thanks

@Polo4444
Copy link

Polo4444 commented Jul 7, 2022

Omg, thanks again !

@goelshubham
Copy link

Thanks mate!! u bro!!

@Polo4444
Copy link

How to do it for net maps, per example:
map[string]map[string]interface{}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment