deepmerge
Deep object merging library for JavaScript. Recursively merges two or more objects, combining nested properties rather than overwriting them. Unlike Object.assign() or spread (...), deepmerge recurses into nested objects. Configurable merge behavior for arrays (concatenate vs overwrite) and custom merge functions. Widely used for merging configuration objects, combining default settings with user overrides, and merging Redux state.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Pure utility library — no network surface. Prototype pollution risk if merging untrusted objects with __proto__ key — sanitize untrusted input before deepmerging.
⚡ Reliability
Best When
You need to recursively merge plain JavaScript objects, especially for configuration merging where you want nested defaults preserved.
Avoid When
You have circular references, class instances with methods, or need only shallow merging (use Object.assign or spread).
Use Cases
- • Merge default configuration with user-provided overrides while preserving nested defaults not overridden
- • Combine multiple configuration sources (file, env, CLI args) with correct precedence and deep merging
- • Merge partial Redux state updates with existing state without losing non-updated nested properties
- • Deep clone objects by merging into an empty object: deepmerge({}, originalObject)
- • Combine API response objects from multiple sources when building aggregated data structures
Not For
- • Shallow merges — use Object.assign() or spread (...) for shallow one-level merges
- • Handling circular references — deepmerge will infinite loop on circular object references
- • JSON-serializable objects only — class instances, functions, and special objects may not merge correctly
Interface
Authentication
No authentication — utility library.
Pricing
Fully free, MIT licensed.
Agent Metadata
Known Gotchas
- ⚠ Arrays are concatenated by default — deepmerge(['a'], ['b']) produces ['a', 'b']; use arrayMerge option to override: arrayMerge: (dest, src) => src to replace instead
- ⚠ Circular references cause infinite recursion and stack overflow — deepmerge does not handle circular objects; use _.mergeWith with cycle detection for circular references
- ⚠ Class instances lose their prototype — merged objects are plain objects; methods from class instances are not preserved in the merge result
- ⚠ deepmerge creates new objects — both source and destination are unmodified; the return value is a new merged object
- ⚠ deepmerge.all([obj1, obj2, obj3]) merges multiple objects left-to-right — later objects override earlier ones for conflicting scalar values
- ⚠ Date, RegExp, Map, Set objects are not deep-merged — they're treated as primitives and overwritten; use a custom merge function for these types
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for deepmerge.
Scores are editorial opinions as of 2026-03-06.