Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/twin/deepmerge
Go library for deep merging YAML or JSON
https://github.com/twin/deepmerge
deep-merge deepmerge go golang json merge yaml
Last synced: 4 months ago
JSON representation
Go library for deep merging YAML or JSON
- Host: GitHub
- URL: https://github.com/twin/deepmerge
- Owner: TwiN
- License: mit
- Created: 2023-01-07T23:21:40.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-18T14:25:31.000Z (12 months ago)
- Last Synced: 2024-06-21T15:31:30.604Z (8 months ago)
- Topics: deep-merge, deepmerge, go, golang, json, merge, yaml
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deepmerge
![test](https://github.com/TwiN/deepmerge/workflows/test/badge.svg?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/TwiN/deepmerge)](https://goreportcard.com/report/github.com/TwiN/deepmerge)
[![Go version](https://img.shields.io/github/go-mod/go-version/TwiN/deepmerge.svg)](https://github.com/TwiN/deepmerge)
[![Go Reference](https://pkg.go.dev/badge/github.com/TwiN/deepmerge.svg)](https://pkg.go.dev/github.com/TwiN/deepmerge)Go library for deep merging YAML or JSON files.
## Usage
### YAML
```go
package mainimport (
"github.com/TwiN/deepmerge"
)func main() {
dst := `
debug: true
client:
insecure: true
users:
- id: 1
firstName: John
lastName: Doe
- id: 2
firstName: Jane
lastName: Doe`
src := `
client:
timeout: 5s
users:
- id: 3
firstName: Bob
lastName: Smith`
output, err := deepmerge.YAML([]byte(dst), []byte(src))
if err != nil {
panic(err)
}
println(string(output))
}
```Output:
```yaml
client:
insecure: true
timeout: 5s
debug: true
users:
- firstName: John
id: 1
lastName: Doe
- firstName: Jane
id: 2
lastName: Doe
- firstName: Bob
id: 3
lastName: Smith
```### JSON
```go
package mainimport (
"github.com/TwiN/deepmerge"
)func main() {
dst := `{
"debug": true,
"client": {
"insecure": true
},
"users": [
{
"id": 1,
"firstName": "John",
"lastName": "Doe"
},
{
"id": 2,
"firstName": "Jane",
"lastName": "Doe"
}
]
}`
src := `{
"client": {
"timeout": "5s"
},
"users": [
{
"id": 3,
"firstName": "Bob",
"lastName": "Smith"
}
]
}`
output, err := deepmerge.JSON([]byte(dst), []byte(src))
if err != nil {
panic(err)
}
println(string(output))
}
```Output:
```json
{
"client": {
"insecure": true,
"timeout": "5s"
},
"debug": true,
"users": [
{
"firstName": "John",
"id": 1,
"lastName": "Doe"
},
{
"firstName": "Jane",
"id": 2,
"lastName": "Doe"
},
{
"firstName": "Bob",
"id": 3,
"lastName": "Smith"
}
]
}
```