Created
June 5, 2021 07:36
-
-
Save cuongld2/6f5584d2b8d72257d4e4e5a6c3f45ae2 to your computer and use it in GitHub Desktop.
Retrieve variant_id from complex json
This file contains 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
var mapResp map[string]interface{} | |
if err := json.NewDecoder(res.Body).Decode(&mapResp); err == nil { | |
// fmt.Println(`&mapResp:`, &mapResp, "\n") | |
// fmt.Println(`mapResp["hits"]:`, mapResp["hits"]) | |
for _, value := range mapResp["hits"].(map[string]interface{}) { | |
if reflect.TypeOf(value).Kind() != reflect.Float64 { | |
for _, each := range value.([]interface{}) { | |
fmt.Println(((each.(map[string]interface{}))["_source"]).(map[string]interface{})["variant_id"]) | |
// key == id, label, properties, etc | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment