DevTools Logo

JSON Merger

JSON Merger

Combine JSON documents with explicit array strategies, per-path overrides and merge-patch mode.

Runs in your browser
Try an example

Documents

2 of 5 panes · left to right precedence

Merged JSON

No documents to merge yet

Paste two JSON documents or load an example.

JSON Merger folds documents left to right so the last document wins on conflicts. Objects merge recursively; arrays can be concatenated, de-duplicated, appended-new-only or replaced; scalars can be right-wins or left-wins. Per-path overrides such as services.*.ports change the strategy for one subtree, and patch mode applies RFC 7386 semantics where null deletes a key. Every right-side decision is listed in a conflict report, and prototype-pollution keys are kept as inert data properties with a warning.

Examples

Layered config

Input
{"port":3000,"db":{"host":"localhost"}} + {"port":8080,"db":{"user":"app"}}
Output
{"port":8080,"db":{"host":"localhost","user":"app"}}

The scalar override wins while nested database keys are combined.

Deduplicated tags

Input
{"tags":["a","b"]} + {"tags":["b","c"]} with concat-unique
Output
{"tags":["a","b","c"]}

Duplicate values are removed by canonical JSON equality, including object items.

Merge patch deletion

Input
{"keep":1,"remove":2} + {"remove":null,"add":3} in patch mode
Output
{"keep":1,"add":3}

The null patch operation deletes the key and is recorded in the decision table.

Per-path override

Input
{"services":{"web":{"ports":[80]}}} + {"services":{"web":{"ports":[443]}}} with services.*.ports → replace
Output
{"services":{"web":{"ports":[443]}}}

A wildcard segment matches the service name so only ports use the replace strategy.

About this tool

JSON Merger combines two to five JSON documents into one. Documents are folded left to right, so later documents have higher precedence: objects merge recursively, and a scalar in the later document replaces the earlier value. The conflict table lists every decision so you can see exactly what won.

Array handling is explicit rather than implicit. Choose concat, concat-unique, append-new-only or replace globally, then override individual paths such as services.*.ports. Exact paths beat wildcard paths, and replace-object lets a later document replace an entire subtree instead of merging into it.

RFC 7386 JSON Merge Patch mode is available for config APIs: a null value deletes a key, arrays replace wholesale and non-object patches replace the target. Deletions are surfaced as conflict rows so a patch cannot silently drop data. All parsing and merging happens in your browser; no document is uploaded.

What this tool does not do

  • The input must be valid JSON; JSON5, comments and trailing commas are not accepted.
  • Up to five documents are supported per merge.
  • Integers beyond 2^53 cannot be represented exactly by JSON.parse and may be rounded before merging.
  • The conflict report is capped at 2,000 entries to keep the UI responsive.
  • Numbers of documents, not schemas, are validated: the tool does not check types against a JSON Schema.

How to use this tool

  1. Paste the documents

    Fill the first pane with the base document and each later pane with an override. Add up to five panes with the Add document button.

  2. Choose merge semantics

    Select the array strategy and scalar direction. Turn on patch mode only when your second document is an RFC 7386 patch.

  3. Add path overrides if needed

    In code, overrides are { path, strategy } entries; exact paths take priority over wildcard segments such as services.*.ports.

  4. Inspect and copy

    The merged JSON updates live. Review the decision table, then copy or download the result.

Use cases

Layer application config

Combine defaults, environment settings and local overrides without losing nested keys.

Assemble fixtures

Merge shared fixture fragments with scenario-specific overrides before running tests.

Build API payloads

Compose a default response body with a partial override document.

Apply merge patches

Apply RFC 7386 patches from a config API and see every deletion explicitly.

Array strategies

StrategyResult of [1,2] merged with [2,3]
concat[1,2,2,3] — every item in order
concat-unique[1,2,3] — canonical-JSON dedupe across both sides
append-new[1,2,3] — new incoming items appended; duplicates inside the incoming array are kept
replace[2,3] — the right-hand array wins wholesale
replace-object (per path)Replaces the entire object at that path instead of deep merging it
merge-patch modeArrays always replace; null deletes an existing key

Precedence is always left to right: document 1 is the base and the last document has the final say.

Common mistakes

Mistake:Expecting Object.assign-style deep merging from one line of code.

Fix:Shallow merges drop nested keys; this tool walks every level and reports overrides.

Mistake:Using concat-unique when duplicate items in the incoming array are meaningful.

Fix:Choose append-new-only: it compares against the accumulated side and keeps incoming duplicates.

Mistake:Leaving patch mode on for ordinary documents.

Fix:In patch mode null deletes keys. Switch it off when null is a legitimate value.

Mistake:Assuming numeric-string keys keep their written order.

Fix:JavaScript orders integer-like keys numerically; use sort keys when canonical ordering matters.

Mistake:Worrying about __proto__ keys in a merged config.

Fix:The tool keeps them as inert own data properties and warns rather than changing object prototypes.

Frequently asked questions

What is the difference between a shallow and a deep merge?

A shallow merge only replaces top-level keys, so a nested object from the base document is lost when the same key appears in an override. A deep merge recurses into objects and keeps untouched nested keys. This tool deep merges objects by default and records every override in the decision table.

How are arrays merged?

You choose the policy: concat keeps every item from both sides; concat-unique removes duplicates by canonical JSON equality; append-new-only appends incoming items that are not already in the accumulated array; replace keeps only the later array. Per-path overrides let different arrays use different policies.

Which document wins on conflicts?

Documents are folded left to right, so the last pane with a value for a key wins. The decision table shows each winning value's path and the strategy that was applied. You can switch scalars to left-wins if you need the opposite precedence.

What is RFC 7386 merge patch?

It is a small JSON document format for partial updates: objects are merged recursively, arrays and scalars replace existing values, and a null value deletes the target key. Enable patch mode only when your override document follows those rules; otherwise null stays an ordinary value.

Can I override the strategy for a specific path?

Yes. Path overrides match exact paths or wildcard segments, so a pattern like services.*.ports can apply the replace strategy to every service's ports array. Exact paths take priority over wildcards, and replace-object replaces a whole subtree instead of merging into it.

Is my JSON uploaded anywhere?

No. Parsing, merging, diffing and formatting all run locally in your browser. Nothing is sent to a server, and no document is persisted to storage.

References & standards