Skip to content

Instantly share code, notes, and snippets.

@KernelPanicAUS
Created December 23, 2018 15:52
Show Gist options
  • Save KernelPanicAUS/680b6f02c3671ef778f71006883762cf to your computer and use it in GitHub Desktop.
Save KernelPanicAUS/680b6f02c3671ef778f71006883762cf to your computer and use it in GitHub Desktop.
Merging JSON structures in go without explicit struct mappings
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