Home → Merge JSON Objects Online

Merge JSON Objects Online

Merge two or more JSON objects into one with shallow or deep merge.

About This Tool

Merge two or more JSON objects into one with shallow or deep merge. This tool runs entirely in your browser — no data is ever sent to a server. Free to use, no account required.

How JSON Merge Works

JSON merge combines two JSON objects into one, with configurable rules for handling overlapping keys and nested structures.

Shallow Merge

Combines top-level keys only. If both objects share a key, the right-hand value wins. Nested objects under the same key are treated as atomic values and replaced entirely — no recursive merging occurs.

Deep Merge

Recursively merges nested objects at every level. Instead of replacing a nested object, it merges the nested keys too, letting both sides contribute values. This is ideal for configuration merging use cases.

JSON Merge Use Cases

Merging JSON is a common operation in configuration management, data aggregation, and API composition.

Merging Configuration Files

A common pattern is a base configuration (defaults) merged with environment-specific overrides. Deep merge lets environment settings override only the specific keys that differ, while inheriting all defaults automatically.

Combining API Responses

When assembling a data object from multiple API endpoints — such as a user profile from one endpoint and permissions from another — merge combines them into a single coherent object.

Frequently Asked Questions

What is the difference between shallow and deep JSON merge?+
A shallow merge combines only the top-level keys of two objects. If both have a nested object under the same key, the right-hand nested object completely replaces the left-hand one. A deep merge recursively merges nested objects, so both sides contribute their nested keys.
What happens to duplicate keys when merging JSON?+
When both JSON objects contain the same key, the value from the second (right-hand) object takes precedence and overwrites the first. Arrays are replaced, not concatenated, in most merge strategies. Use the advanced merge tool if you need array concatenation.
Can I merge more than two JSON objects?+
This tool merges two JSON objects at a time. To merge three or more, merge the first two, copy the result, then merge that with the third. The result is the same as a left-to-right sequential merge where later objects override earlier ones.
Is JSON merge the same as JSON patch?+
No. JSON merge produces a new combined object. JSON Patch (RFC 6902) is a set of explicit operations (add, remove, replace, move, copy, test) that describe changes to apply to a document. Merge is simpler; patch is more precise and supports removals via null values.

JSON Merge Strategies Explained

Merging JSON objects has different semantics depending on strategy. Choosing the wrong strategy for nested objects is the most common source of merge bugs.

Shallow vs Deep Merge

const base = {
  "user": {"name": "Alice", "age": 30},
  "theme": "dark"
};
const override = {
  "user": {"age": 31, "role": "admin"},
  "language": "en"
};

// Shallow merge (Object.assign) — overwrites nested
const shallow = Object.assign({}, base, override);
// { user: {age:31, role:"admin"}, theme:"dark", language:"en" }
// NOTE: user.name is LOST!

// Deep merge — recursively combines nested
// { user: {name:"Alice", age:31, role:"admin"}, theme:"dark", language:"en" }

Merge Strategy Comparison

MethodStrategyBehavior
Object.assign()ShallowNested objects replaced entirely
Spread {...a, ...b}ShallowSame as Object.assign for top level
lodash.merge()DeepRecursively combines nested objects
JSON Patch (RFC 6902)PatchExplicit add/remove/replace operations
JSON Merge Patch (RFC 7396)Deep null-deletenull values delete keys

Deep Merge in Python

import copy

def deep_merge(base, override):
    result = copy.deepcopy(base)
    for key, value in override.items():
        if key in result and isinstance(result[key], dict) and isinstance(value, dict):
            result[key] = deep_merge(result[key], value)
        else:
            result[key] = copy.deepcopy(value)
    return result

JSON Merge Strategies Explained

The merge strategy you choose determines what happens when both objects share the same key — especially for nested objects and arrays. Picking the wrong strategy is the most common source of subtle data loss in JSON merging.

Shallow Merge (Object.assign / spread)

const a = { x: 1, nested: { y: 2 } };
const b = { z: 3, nested: { w: 4 } };

// Shallow merge — nested.y is LOST
const result = { ...a, ...b };
// { x: 1, z: 3, nested: { w: 4 } }  ← nested.y gone!

Deep Merge (recursive)

// Deep merge — nested properties combined
const result = deepMerge(a, b);
// { x: 1, z: 3, nested: { y: 2, w: 4 } }  ← both kept!

// Simple deep merge implementation
function deepMerge(target, source) {
  const result = { ...target };
  for (const key in source) {
    if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
      result[key] = deepMerge(result[key] || {}, source[key]);
    } else {
      result[key] = source[key];
    }
  }
  return result;
}

JSON Merge Use Cases

Different real-world scenarios call for different merge behaviors. Knowing which strategy to use in each context prevents data loss and unexpected overrides.

Use Case Merge Type Example
Config file overrideDeep mergeBase config + environment overrides
API response updateShallow mergePATCH request with updated fields
Array concatenationArray appendMerge two lists without deduplication
Default + user settingsDeep mergeApp defaults merged with user preferences
Translation filesDeep mergeBase locale merged with overrides

Explore more tools: All JSON Tools | Validator | Pretty Print | JSON Diff