JSON Object Merger

Merges two JSON objects into one. Shallow mode spreads B's top-level keys over A's; deep mode recursively merges nested objects too, while arrays at a shared key are replaced wholesale by B's version rather than concatenated. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-24

Overview

Introduction

Combining a base config with an override object, or merging two partial records into one, comes up constantly, and doing it right for nested objects means writing recursive merge logic most people don't want to hand-roll each time.

This tool merges two JSON objects for you, with a toggle between a simple shallow spread and a full recursive deep merge.

What Is JSON Object Merger?

A merge tool that combines two JSON objects, A as the base and B as the overrides, into a single result, in either shallow or deep mode.

Shallow mode is exactly JavaScript's object spread behavior; deep mode extends that by recursing into any key where both objects have a nested plain object, rather than letting B's object replace A's outright.

How JSON Object Merger Works

Both inputs are parsed and confirmed to be JSON objects (not arrays or scalars) at the top level. In shallow mode, the result is simply {...a, ...b}.

In deep mode, the tool walks B's keys one at a time: if the same key holds a plain object in both A and the merged-so-far result, it recurses into those two objects and merges them the same way; otherwise B's value at that key replaces whatever was there, which is also what happens for arrays, since arrays are never treated as "plain objects" for the recursion check.

When To Use JSON Object Merger

Use it to layer an override object (environment-specific settings, a user's custom preferences) on top of a base config object.

Deep mode is the better fit when both objects have nested structure you want combined field-by-field rather than one nested object wholesale replacing the other.

Features

Advantages

  • Offers both shallow (spread-equivalent) and deep (recursive) merge modes in one tool.
  • Deep mode correctly recurses into arbitrarily nested shared objects, not just one level.
  • Reports parse or type errors per side, so you know exactly which input to fix.

Limitations

  • Deep mode never merges arrays element-by-element; a shared array key is always replaced wholesale by B's version.
  • Only merges exactly two objects; merging three or more config layers requires running the tool twice, feeding the first result back in as A.

Examples

Shallow merge

Input

A: {"a":1,"nested":{"x":1}}
B: {"nested":{"y":2}}

Output

{
  "a": 1,
  "nested": { "y": 2 }
}

B's "nested" object entirely replaces A's in shallow mode, so A's x key is lost.

Deep merge

Input

A: {"a":1,"nested":{"x":1}}
B: {"nested":{"y":2}}

Output

{
  "a": 1,
  "nested": { "x": 1, "y": 2 }
}

In deep mode, the shared "nested" object is merged recursively, keeping both x and y.

Best Practices & Notes

Best Practices

  • Use deep mode whenever both sides have nested config sections you expect to combine, not replace.
  • Remember arrays always replace wholesale in deep mode; if you need array items combined too, use Merge JSON Arrays on that specific field separately.
  • Treat A as the base/defaults and B as the overrides for the clearest mental model, since B always wins conflicts in both modes.

Developer Notes

The recursion check (isPlainObject(aValue) && isPlainObject(bValue)) explicitly excludes arrays, since Array.isArray(x) && typeof x === "object" is true for arrays too; without that exclusion, deep merge would try to recursively merge array indices as object keys instead of replacing arrays wholesale as documented.

JSON Object Merger Use Cases

  • Layering environment-specific config over a base config object
  • Merging a user's custom settings over application defaults
  • Combining two partial JSON records into one complete object

Common Mistakes

  • Expecting deep mode to merge arrays index-by-index; arrays are always replaced wholesale, never merged.
  • Using shallow mode when nested config sections need combining; shallow mode lets B's nested object silently replace all of A's fields at that key.

Tips

  • If you need to merge two arrays instead of two objects, use Merge JSON Arrays.
  • Run Compare JSON Arrays or JSON Diff first if you want to see exactly what would change before committing to a merge.

References

Frequently Asked Questions