Created
December 23, 2018 15:52
-
-
Save KernelPanicAUS/680b6f02c3671ef778f71006883762cf to your computer and use it in GitHub Desktop.
Merging JSON structures in go without explicit struct mappings
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 ( | |
"encoding/json" | |
"fmt" | |
) | |
func main() { | |
inputJSON := `{"environment": "production", "runbook":"http://url","message":"there is a problem"}` | |
out := map[string]interface{}{} | |
json.Unmarshal([]byte(inputJSON), &out) | |
out["name"] = "thomas" | |
out["command"] = "sudo make me a sammich" | |
out["status"] = "ready" | |
out["environment"] = "stage" | |
outputJSON, _ := json.Marshal(out) | |
fmt.Printf("%s\n", outputJSON) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment