npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@gradientedge/merge-jsonc

v1.0.2

Published

JSON/JSONC/JSON5 deep-merger CLI for Node 22+

Readme

🧩 merge-jsonc

Secure, fast JSON / JSONC / JSON5 deep-merging utility and CLI for Node 22+
Built for composable configuration files such as Wrangler, Vite, or Next.js.


✨ Overview

merge-jsonc lets you combine multiple .json, .jsonc, or .json5 files in order, producing a single merged output where later files override earlier ones.
It's designed for config layering (base → local → environment), with:

  • Deep merge support (deepmerge under the hood)
  • 🧠 Incremental builds — skips work when inputs or content haven't changed
  • 🔒 Path-safe — resists directory-traversal and symlink escapes (Snyk-friendly)
  • 🧾 Multi-format aware — parses JSON, JSONC (comments), and JSON5 (extended syntax)
  • 🪶 ESM-only, Node 22+ — zero legacy baggage

📦 Installation

npm install @gradientedge/merge-jsonc

🚀 Quick Start

# Merge multiple config files
merge-jsonc --out final.json base.json dev.jsonc local.json5

# With backup and preview
merge-jsonc --backup --dry-run --out config.json *.jsonc

📖 Usage

CLI

merge-jsonc [options] <input-files...>

Options:
  -o, --out           Output file path                    [default: "combined.jsonc"]
      --skip-missing  Ignore missing input files         [boolean] [default: false]
      --min           Minified output                     [boolean] [default: false]
      --dry-run       Preview without writing files      [boolean] [default: false]
      --backup        Create .bak before overwriting     [boolean] [default: false]
      --indent        Custom indentation spaces          [number]
      --array-merge   Array merge strategy               [choices: "replace", "concat"] [default: "replace"]
  -h, --help          Show help
  -v, --version       Show version

Programmatic API

import { mergeJsonc } from "@gradientedge/merge-jsonc";

const result = mergeJsonc({
  inputs: ["base.json", "dev.jsonc", "local.json5"],
  out: "config.json",
  skipMissing: true,
  arrayMerge: "replace", // or "concat"
});

console.log(result.wrote ? "Merged!" : result.reason);

🔀 Array Merge Strategies

By default, merge-jsonc replaces arrays when merging. You can configure this behavior:

Replace (default)

Arrays from later files completely replace arrays from earlier files:

// base.json
{ "items": [1, 2, 3] }

// override.json
{ "items": [4, 5] }

// Result with --array-merge replace (default)
{ "items": [4, 5] }
merge-jsonc base.json override.json --out result.json
# or explicitly:
merge-jsonc base.json override.json --out result.json --array-merge replace

Concat

Arrays are concatenated together:

// base.json
{ "items": [1, 2, 3] }

// override.json
{ "items": [4, 5] }

// Result with --array-merge concat
{ "items": [1, 2, 3, 4, 5] }
merge-jsonc base.json override.json --out result.json --array-merge concat

Configuration File

You can also set the array merge strategy in your config file:

// .merge-jsonc.config.mjs
export default {
  arrayMerge: "concat",
  backup: true,
  pretty: true,
};

🧪 Examples

See the examples/ directory for real-world usage patterns:

  • Vite Config: Layer base, dev, and local Vite configurations
  • Wrangler Config: Merge Cloudflare Workers configurations
  • JSON5 Features: Demonstrate JSON5 syntax with comments and trailing commas

🛡️ Security Features

  • Path Traversal Protection: Prevents ../ attacks and symlink escapes
  • File Type Validation: Only processes .json, .jsonc, and .json5 files
  • Atomic Writes: Uses temporary files to prevent corruption
  • Snyk Compliant: Passes security audits for enterprise use

🔧 Development

# Install dependencies
npm install

# Format code (ensures JSONC files have no trailing commas)
npm run format

# Check formatting
npm run format:check

# Run linting
npm run lint

# Run tests (66 comprehensive tests)
npm test

# Build the project
npm run build

# Test locally
npm run prepublishOnly

📝 License

MIT © Gradient Edge