Home → Merge JSON Objects Online
Merge two or more JSON objects into one with shallow or deep merge.
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.
JSON merge combines two JSON objects into one, with configurable rules for handling overlapping keys and nested structures.
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.
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.
Merging JSON is a common operation in configuration management, data aggregation, and API composition.
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.
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.
Merging JSON objects has different semantics depending on strategy. Choosing the wrong strategy for nested objects is the most common source of merge bugs.
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" }
| Method | Strategy | Behavior |
|---|---|---|
| Object.assign() | Shallow | Nested objects replaced entirely |
| Spread {...a, ...b} | Shallow | Same as Object.assign for top level |
| lodash.merge() | Deep | Recursively combines nested objects |
| JSON Patch (RFC 6902) | Patch | Explicit add/remove/replace operations |
| JSON Merge Patch (RFC 7396) | Deep null-delete | null values delete keys |
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
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.
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 — 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;
}
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 override | Deep merge | Base config + environment overrides |
| API response update | Shallow merge | PATCH request with updated fields |
| Array concatenation | Array append | Merge two lists without deduplication |
| Default + user settings | Deep merge | App defaults merged with user preferences |
| Translation files | Deep merge | Base locale merged with overrides |
Explore more tools: All JSON Tools | Validator | Pretty Print | JSON Diff