Created
May 7, 2019 08:22
-
-
Save bonfy/b7c48d0caa6db2dfaf28c2621326c244 to your computer and use it in GitHub Desktop.
Go merge json
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) | |
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