mergeon v0.4.2
Mergeon
Loading extendable JSON structures:
- Load data from different JSON files
- Use wildcards/globs
- Override inherited values
- Merge data
- Customize merging
Contents
Installation
npm
npm i -S mergeonyarn
yarn add mergeonExamples
Simple use case
Load data from different JSON file and override values:
entry.json
{
"_extends": "./default-data.json",
"title": "New title",
"image": {
"alt": "New alt value"
}
}default-data.json
{
"title": "Default title",
"image": {
"src": "path/to/default/image.jpg",
"alt": "Default alt value"
}
}Result
{
"title": "New title",
"image": {
"src": "path/to/default/image.jpg",
"alt": "New alt value"
}
}Target path
Define a target path by using special syntax (<extendKey>:<targetPath>):
entry.json
{
"_extends:target.path": "./default-data.json"
}default-data.json
{
"title": "Default title"
}Result
{
"target": {
"path": {
"title": "Default title"
}
}
}Wildcards
Load multiple files by adding wildcards:
entry.json
{
"_extends:buttons": "./buttons/*.json"
}buttons/primary.json
{
"type": "primary"
}buttons/secondary.json
{
"type": "secondary"
}Result
{
"buttons": {
"primary": {
"type": "primary"
},
"secondary": {
"type": "secondary"
}
}
}Additional examples
See test directory for additional examples, including wildcards, globstars, customized merging and many more.
Usage
JavaScript API
import mergeon from 'mergeon';
mergeon
.load({
entry: 'data/entry.json',
})
.then(result => {
const jsonString = JSON.stringify(result.data, null, 2);
/* ... */
})
.catch(error => {
/* ... */
});CLI
mergeon data/entry.json > output.jsonOptions
entry
| Type | Default | Required |
|---|---|---|
string | object | undefined | yes |
context
| Type | Default | Required |
|---|---|---|
string | process.cwd() | no |
Note: This option is not available to CLI
extendKey
| Type | Default | Required |
|---|---|---|
string | "_extends" | no |
mergeCustomizer
| Type | Default | Required |
|---|---|---|
function | undefined | no |
This function will be passed as customizer to lodash’s _.mergeWith method.
Note: This option is not available to CLI
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago