Skip to content

Instantly share code, notes, and snippets.

@bonfy
Created May 7, 2019 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonfy/b7c48d0caa6db2dfaf28c2621326c244 to your computer and use it in GitHub Desktop.
Save bonfy/b7c48d0caa6db2dfaf28c2621326c244 to your computer and use it in GitHub Desktop.
Go merge json
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)
newJSON := `{"environment": "prod", "item":"hello"}`
new := map[string]interface{}{}
json.Unmarshal([]byte(newJSON), &new)
for item := range new {
out[item] = new[item]
}
outputJSON, _ := json.Marshal(out)
fmt.Printf("%s", outputJSON)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment