Created
August 18, 2016 06:57
-
-
Save darcwader/fa83a0b538242f65a40b07f49e0184ed to your computer and use it in GitHub Desktop.
golang keeping additional json fields as is
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
) | |
func main() { | |
str := `{"hello":{"nested":{"world":"!"}}}` | |
fmt.Println("input string : ", str) | |
s := struct { | |
Hello map[string]interface{} | |
}{} | |
err := json.Unmarshal([]byte(str), &s) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("struct : ", s) | |
b, err := json.Marshal(s) | |
fmt.Println("marshalled back(notice cap hello): ", string(b)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment