1
0
Fork 0

Adding upstream version 0.2.2.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-16 21:59:49 +02:00
parent 975d1f9be4
commit 0759e85aad
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
14 changed files with 837 additions and 0 deletions

31
json.go Normal file
View file

@ -0,0 +1,31 @@
package deepmerge
import (
"encoding/json"
)
// JSON merges the contents of src into dst
func JSON(dst, src []byte, optionalConfig ...Config) ([]byte, error) {
var cfg Config
if len(optionalConfig) > 0 {
cfg = optionalConfig[0]
} else {
cfg = Config{PreventMultipleDefinitionsOfKeysWithPrimitiveValue: true}
}
var dstMap, srcMap map[string]interface{}
err := json.Unmarshal(dst, &dstMap)
if err != nil {
return nil, err
}
err = json.Unmarshal(src, &srcMap)
if err != nil {
return nil, err
}
if dstMap == nil {
dstMap = make(map[string]interface{})
}
if err = DeepMerge(dstMap, srcMap, cfg); err != nil {
return nil, err
}
return json.Marshal(dstMap)
}