Merge two JSON documents

Runs locally

Combine two JSON documents. The right-hand document wins on conflicts.

Nested objects merge recursively; arrays are replaced.

Base document

Overriding document

Merged

11 lines

{
"name": "service-a",
"replicas": 3,
"env": {
"LOG_LEVEL": "debug",
"REGION": "eu"
},
"ports": [
9090
]
}

About merging JSON documents

How it works in 4 steps · 4 common use cases · 3 questions answered

How it works

  1. 1.Paste the base document on the left and the overriding one on the right.
  2. 2.Choose deep merge to combine nested objects key by key, or shallow to replace at the top level only.
  3. 3.Where both documents set the same key to a scalar, the second one wins.
  4. 4.Copy the merged result.

Common use cases

  • •Applying an environment override on top of a base configuration
  • •Combining a defaults object with user settings the way a config library would
  • •Layering a patch onto a fixture without editing the original
  • •Working out what the effective config will be before deploying it

FAQ

Why are arrays replaced instead of concatenated?

Because that is what config overrides almost always mean. If a base sets three allowed hosts and an override sets one, concatenating would silently keep the other two. Replacement makes the override authoritative.

What is the difference between deep and shallow merge?

Shallow merge only looks at top-level keys, so an object in the second document replaces the whole object in the first. Deep merge walks into nested objects and merges them key by key.

How is null treated in the overriding document?

As a value, so it overwrites whatever the base had. To drop a key entirely, remove it from both documents or clean the result with Remove Nulls.