JSON Deep Merge — Combine Multiple JSON Objects
Understanding the Basics
Merging JSON objects is a deceptively complex operation. JavaScript's Object.assign and the spread operator ({...a, ...b}) perform only shallow merges: if both objects have a key whose value is itself an object, the second object's value completely replaces the first instead of being recursively merged. Deep merging recursively combines nested objects at every level, preserving values from both sources unless they conflict. This distinction matters enormously in configuration management: merging a default config with an environment-specific override should preserve all default keys that the override doesn't touch, while allowing the override to modify specific nested settings. Configuration layering in tools like webpack, Jest, and Babel all rely on deep merge semantics. JSON merge is also essential in event sourcing (merging partial state updates), API aggregation (combining responses from multiple microservices), and data migration (backfilling missing fields from a defaults document). Our tool performs a recursive deep merge with configurable conflict resolution: the second document wins (right-wins) by default, but you can choose left-wins or to merge arrays rather than replace them.
How to Use the Tool
- Paste the base JSON object (the lower-priority source) into the left editor.
- Paste the override JSON object (the higher-priority source) into the right editor.
- Choose the array conflict strategy: "Replace" (right overwrites left array) or "Concat" (arrays are concatenated).
- Click "Merge" — the tool recursively combines both objects, resolving conflicts per your chosen strategy.
- Review the merged output and copy or download it for use in your configuration or application.
Key Features & Specifications
- Recursive deep merge: nested objects are merged at every level, not shallowly replaced
- Configurable array conflict strategy: replace (default), concatenate, or union (deduplicated)
- Right-wins conflict resolution by default: the second (override) document takes precedence
- Clearly highlights which keys came from the left source, right source, or both
- Handles merging of three or more documents via iterative merging
Frequently Asked Questions (FAQ)
- Q:What happens when both objects have the same key with scalar values?
- For scalar values (strings, numbers, booleans), the right (override) document always wins by default. If you need left-wins semantics (preserve original values), toggle the conflict resolution mode in the toolbar.
- Q:How are arrays merged when both documents contain the same array key?
- By default, the right document's array replaces the left's entirely (like Object.assign). In "concat" mode, both arrays are joined. In "union" mode, both arrays are joined and then deduplicated using deep equality comparison.
- Q:Can I merge more than two documents?
- Yes. The tool supports multi-document merging by adding additional sources. Each successive document is merged into the running result from left to right, with the rightmost document having highest priority.