Merge JSON CLI Tool
raw JSON →The `merge-json-cli` package (current stable version 1.0.4) is a lean command-line utility designed for merging multiple JSON files into a single output. It introduces a custom "spread syntax" (`"..."`) directly within JSON objects and arrays, allowing developers to declaratively reference external JSON files or specific paths within them using JSON pointers. This enables dynamic composition of complex configurations from modular JSON fragments. The tool supports both object and array merging, including the use of glob patterns for array-based merges. As a CLI tool, its release cadence is driven by feature enhancements and bug fixes rather than a fixed schedule. Its primary differentiator is the in-JSON spread syntax, providing an intuitive way to manage hierarchical data structures across multiple files. It requires Node.js version 18.3.0 or higher.
Common errors
error Error: ENOENT: no such file or directory, open 'path/to/referenced-file.json' ↓
"..." value within your JSON configuration, or ensure the referenced file is present at that location. error SyntaxError: Unexpected token '...' ↓
error Error: The 'merge-json-cli' package requires Node.js version >=18.3.0. You are running vX.Y.Z. ↓
nvm or by downloading the latest LTS release from the official Node.js website. Warnings
gotcha The `merge-json-cli` package requires Node.js version 18.3.0 or higher. Running it with an older version will result in an error. ↓
gotcha Paths specified in the JSON spread syntax (`"..."`) must be valid file paths or JSON pointers. Incorrectly formatted paths will lead to file not found errors or parsing issues. ↓
gotcha Referenced JSON files must exist and be accessible relative to the primary input file or current working directory. If a file cannot be found, the merge operation will fail. ↓
gotcha Command line arguments require correct syntax for input (`--in|-i`) and output (`--out|-o`). Misspellings or incorrect formatting will prevent the tool from executing. ↓
Install
npm install merge-json-cli yarn add merge-json-cli pnpm add merge-json-cli Quickstart
npx merge-json-cli --in ./input.json --out ./output.json
# Example input.json:
# {
# "configName": "MyApp",
# "version": "1.0.0",
# "...": "./features.json",
# "settings": {
# "theme": "dark"
# }
# }
# Example features.json (referenced by input.json):
# {
# "featureA": true,
# "featureB": false
# }
# The command will merge input.json, incorporating features.json,
# and write the result to output.json.