Last active
July 14, 2021 05:20
-
-
Save u-r-w/8f9e72a15c5d1c61326f80a1d1ab0e60 to your computer and use it in GitHub Desktop.
Run this code on playground: https://play.golang.org/p/w_SoK-WMgVJ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"encoding/json" | |
) | |
var b = []byte(`{ | |
"Module": [ | |
{ | |
"Containers": "HomeMainFeature2", | |
"Components" : "MainFeature2", | |
"Molecules": [ | |
"Gojek_service" | |
] | |
} | |
] | |
}`) | |
func main() { | |
var mappedJson map[string]interface{} | |
json.Unmarshal([]byte(b), &mappedJson) | |
module := mappedJson["Module"].([]interface{}) | |
for i := range module { | |
container := module[i].(map[string]interface{})["Containers"].(string) | |
fmt.Println(container) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://umarudy.medium.com/go-traversing-mapped-json-interface-dc361b906725