MergeJSON

How to Merge JSON Files: 4 Methods (Online, Node, Python, jq)

Need to combine multiple JSON files into one? Here are four reliable ways to merge JSON — using a browser tool, JavaScript, Python, and the jq command line.

Published January 15, 2026

Combining multiple JSON files into a single document is one of the most common data chores in software work — and there are several good ways to do it depending on whether you want something instant, scriptable, or part of a pipeline. This guide covers four reliable methods, from a zero-setup browser tool to one-line shell commands.

Method 1: Merge JSON files online (no setup)

The fastest way to merge JSON is in your browser. With our merge tool you drag in two or more .json files, choose how you want them combined, and download the result — all without installing anything or sending your data to a server.

It is ideal when you want to:

  • merge files right now without writing code,
  • control exactly how nested objects and arrays combine,
  • validate inputs and catch syntax errors before merging,
  • keep sensitive data on your own machine.

Because everything runs client-side, it is both the quickest and the most private option for one-off merges.

Method 2: Merge JSON in Node.js

For programmatic merges, JavaScript’s spread operator handles the shallow case in one line:

import { readFileSync, writeFileSync } from "node:fs";

const a = JSON.parse(readFileSync("a.json", "utf8"));
const b = JSON.parse(readFileSync("b.json", "utf8"));

const merged = { ...a, ...b }; // b wins on conflicts
writeFileSync("merged.json", JSON.stringify(merged, null, 2));

The spread operator only merges the top level, though. For nested objects you need a deep merge. A small recursive helper does the job:

function deepMerge(a, b) {
  const out = { ...a };
  for (const key of Object.keys(b)) {
    if (isObject(a[key]) && isObject(b[key])) {
      out[key] = deepMerge(a[key], b[key]);
    } else {
      out[key] = b[key];
    }
  }
  return out;
}
const isObject = (v) => v && typeof v === "object" && !Array.isArray(v);

Libraries like lodash.merge provide a battle-tested version if you prefer not to roll your own.

Method 3: Merge JSON in Python

Python’s dict makes shallow merges trivial:

import json

with open("a.json") as f: a = json.load(f)
with open("b.json") as f: b = json.load(f)

merged = {**a, **b}  # or a | b on Python 3.9+

with open("merged.json", "w") as f:
    json.dump(merged, f, indent=2)

For a recursive deep merge:

def deep_merge(a, b):
    out = dict(a)
    for k, v in b.items():
        if isinstance(out.get(k), dict) and isinstance(v, dict):
            out[k] = deep_merge(out[k], v)
        else:
            out[k] = v
    return out

Method 4: Merge JSON with jq

jq is the Swiss-army knife for JSON on the command line. To shallow-merge two files:

jq -s '.[0] * .[1]' a.json b.json > merged.json

The -s (slurp) flag reads all inputs into an array, and * performs a recursive object merge. To concatenate arrays from many files instead:

jq -s 'add' *.json > merged.json

jq shines inside shell scripts and CI pipelines where you are already streaming JSON around.

Which method should you use?

SituationBest method
One-off merge, no setupOnline tool
Inside a Node app or build stepNode.js spread / lodash
Data science or scriptingPython dict merge
Shell pipelines and CIjq

Watch out for arrays and conflicts

Every method has to decide two things: how to merge arrays (concatenate, replace, or de-duplicate?) and which value wins on a key conflict (first or last?). The code samples above replace arrays and let the last input win — that is the most common default, but not always what you want. Our online tool exposes these as explicit options, and our guide to deep vs. shallow merge digs into the trade-offs.

Conclusion

Merging JSON is easy once you pick the right tool for the context. For quick, private, controllable merges, the browser tool is hard to beat. For automation, a few lines of Node, Python, or jq will slot neatly into your workflow.

Ready to merge your JSON?

Combine files or snippets in your browser — free and private.

Open the merge tool

Keep reading