Deep merge two JSON objects

Combine two JSON values with recursive object merging and a chosen array strategy.

freeworks offlinenothing uploaded
ToolJSON Merge
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

Both values are parsed, plain objects merge recursively, scalar conflicts use the later value, and arrays replace, concatenate, or concatenate uniquely according to the selected strategy. The result is serialized with indentation.

  • Array replacement is the least-assumptive default.
  • Alternative list strategies are explicit because arrays have no universal identity key.

Worked example

Deep Merge Objects
Deep merge two configuration objects, combining nested properties
Input
											{"database": {"host": "localhost", "port": 5432}, "logging": {"level": "info"}}
										
Output
												{
  "database": {
    "host": "localhost",
    "port": 5432
  },
  "logging": {
    "level": "info"
  }
}
											

When to use this

Configuration overlays, deployment defaults, and scenario fixtures combine JSON objects.

Edge cases

  • A scalar replacing an object discards the earlier branch.
  • Concatenation preserves duplicates unless unique mode is selected.
  • Different nested types use the later branch.

References