2.0.0 • Published 5 years ago

json-union v2.0.0

Weekly downloads
187
License
ISC
Repository
github
Last release
5 years ago

Build Status

json-union

An es6 library used to merge JSON files that match a set of glob patterns.

features

  • perfoms a shallow or deep merge of all JSON files that match any of the glob patterns
  • writes to stdout if no outfile is provided
  • will create outfile directory and file if it does not exist
  • will overwrite outfile if it does exist
  • can optionally ignore parsing errors
  • asynchronous; returns an es6 promise

installation

$ npm i jsonUnion -g

cli

# simple usage
$ jsonUnion src/**/*.json

# multiple glob patterns
$ jsonUnion src/**/*.json config/**/*.json

# using stdout to write to file
$ jsonUnion src/**/*.json > my.json

# using pipes
$ jsonUnion src/**/*.json | myApp

# saving to file in a directory that does not exist
$ jsonUnion src/**/*.json -o my/new/directory/file.json

# using other options
$ jsonUnion src/**/*.json -d -e ascii -i

options

NameAliasTypeDefaultDescription
--deepMerge-dbooleanfalsemerges JSON files recursively
--encoding-estring'utf8'encoding used to read and write files
--ignoreParseErrors-ibooleanfalseignores any errors that are raised from parsing the JSON file
--outfile-ostringundefinedthe directory and filename of where the merged JSON file should be saved

Note: if --outfile or -o is not provided then the merged JSON is sent to sdtout

module

const jsonUnion = require('json-union').default;

// simple usage
jsonUnion('src/**/*.json')
    .then((json) => console.log(json))
    .catch((error) => console.error(error));

// multiple glob patterns
jsonUnion(['src/**/*.json', 'config/**/*.json'])
    .then((json) => console.log(json))
    .catch((error) => console.error(error));

// with options
jsonUnion('src/**/en.json', {
    deepMerge: true,
    encoding: 'ascii',
    ignoreParseErrors: true,
    outfile: 'dist/public/en.json'
})
    .then((json) => console.log(json))
    .catch((error) => console.error(error));

params

NameTypeDescription
patternsstring, string[]a string or string array of glob patterns to match against
optionsOptions?jsonUnion options object

Options

NameTypeDefaultDescription
deepMergebooleanfalsemerges JSON files recursively
encodingstring'utf8'encoding used to read and write files
ignoreParseErrorsbooleanfalseignores any errors that are raised from parsing the JSON file
outfilestringundefinedthe directory and filename of where the merged JSON file should be saved

Note: if outfile is not provided then no file will be created on the file system

returns

A promise to the merged JSON object

2.0.0

5 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.4

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago