json-bundler
raw JSON → 1.0.0 verified Sat Apr 25 auth: no javascript
json-bundler is a Node.js CLI tool for bundling multiple JSON and JSON5 files into a single merged JSON file. Version 1.0.0 is the initial release. It uses a $ref key to reference other JSON files, supports JSON5 for comments and linebreaks, and offers minification and watch mode. Features include merging with priority for the referencing file and support for referencing npm packages via ~. It is designed for tasks like i18n file organization in Angular or other web projects. Requires Node.js 7.6+.
Common errors
error ENOENT: no such file or directory, open './nonexistent.json' ↓
cause Referenced file path is incorrect or file missing.
fix
Ensure referenced file exists and the path in $ref is correct relative to the referencing file.
error Error: Invalid JSON5 file ↓
cause Referenced JSON5 file has syntax errors.
fix
Validate JSON5 syntax with a JSON5 parser or use valid JSON.
Warnings
gotcha `$ref` paths are relative to the file containing the $ref, not the current working directory. ↓
fix Use paths relative to the file's location.
gotcha When a referenced file contains keys that already exist in the referencing file, the referencing file's values take precedence. ↓
fix Be aware of merge priority: referencing file overrides referenced files.
gotcha Paths starting with `~` are resolved in the project's `node_modules` folder, not user home directory. ↓
fix Use `~package-name/path/file.json` to reference npm packages.
Install
npm install json-bundler yarn add json-bundler pnpm add json-bundler Quickstart
npm install json-bundler --save-dev
# Create entry file: en.json
{
"greeting": "Hello",
"$ref": "./messages/welcome.json"
}
# Referenced file: messages/welcome.json
{
"welcome": "Welcome to our app!"
}
# Run bundler (outputs merged file)
npx json-bundler --entryFile en.json --outFile dist/en.json