Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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"])
}
@Chi89
Copy link

Chi89 commented Sep 9, 2020

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

thaison247 commented Dec 22, 2020

Thanks!

@vishutrilio
Copy link

vishutrilio commented Apr 12, 2021

Thank you so much

@joechen1105
Copy link

joechen1105 commented Jul 15, 2021

THANK YOU!!!

@aldlfkahs
Copy link

aldlfkahs commented Aug 6, 2021

You saved my life

@bharathraj-e
Copy link

bharathraj-e commented Aug 15, 2021

Simple and saving lives

@satyamkb
Copy link

satyamkb commented Sep 28, 2021

Life saver

@brunotrajano-mm
Copy link

brunotrajano-mm commented Dec 21, 2021

Thanks! It helped a lot

@ashmilhussain
Copy link

ashmilhussain commented Feb 10, 2022

how to do this for a nested data

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

@vmpastran
Copy link

vmpastran commented Feb 17, 2022

Merci beaucoup

@sramac2
Copy link

sramac2 commented Feb 17, 2022

Thanks

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