JSON Merge

#1Input
#2Input

Free online JSON Merge tool. One-click merge multiple JSON objects by a chosen strategy (Deep / Shallow / Array Concat / Array Replace) with 4 conflict resolution modes. Ideal for multi-source aggregation, config layering, and i18n consolidation.

Related

What is JSON Merge?

JSON Merge is the operation of combining two or more JSON objects into a new object according to certain rules. It appears extremely frequently in engineering: ① Stitching JSON from multiple microservices into a unified response (BFF layer aggregation); ② Combining base / env / user config under an "environment override" logic to produce the final config (Node.js config, Viper, Spring Cloud Config); ③ Merging, overriding, and supplementing multiple i18n translation files into a complete dictionary; ④ Combining multiple mock data arrays into complete test data; ⑤ Merging multiple API paginated responses into a full dataset.

The hard part is not the "merge" but "how to handle conflicts". There are 4 common conflict resolution strategies: ① **Deep Merge**: Recursively enters nested objects, merging each key individually and only overwriting when leaf nodes conflict — ideal for config layering. ② **Shallow Merge**: Only merges top-level keys, replacing same-named keys in their entirety — simplest semantics, similar to `Object.assign`. ③ **Array Concat**: Concatenates array values into a long array preserving all element order — ideal for API aggregation. ④ **Array Replace**: Replaces array values entirely with the later input — ideal for config override.

At the implementation level, deep merge typically uses stack-based recursion: first check that both sides are plain objects (not arrays, not null), then recursively process each key; when types are inconsistent (e.g. one side is an object, the other is an array for the same name), it generally follows the "last input wins" rule without type conversion. GeekFormat's JSON Merge tool includes all 4 strategies above and lets you switch directly on the page; you can paste 2 to N JSON segments at once, auto-merge in order, and output a uniformly formatted result. The entire merge process happens locally in the browser, original data is not uploaded.

Use Cases

  • Merge multiple microservice API responses into a unified JSON structure for the front-end
  • Aggregate base / dev / prod layered config files into the final config via environment override
  • Merge multiple i18n translation files by language, deduplicate, and complete into a full dictionary
  • Combine multiple mock data arrays or paginated API responses into a complete dataset
  • Front-end component merging default config + user customization + remote A/B experiment config
  • During data migration, merge multiple source systems' JSON exports into a unified downstream format

How to Use

  1. Paste 2 to N JSON segments to be merged into the left input boxes (2 by default), or click "+" to add more inputs
  2. Select a merge strategy from the toolbar dropdown: Deep Merge / Shallow Merge / Array Concat / Array Replace
  3. Click the "Merge" button; the right output box shows the formatted result. If the input has syntax errors, the specific line number and error message are shown
  4. After confirming the result, click "Copy" to put the merged output in the clipboard, or click "Download" to save as merged.json for further formatting, Schema validation, etc.

Features

  • 4 merge strategies: Deep Merge / Shallow Merge / Array Concat / Array Replace, switchable with one click to fit different business scenarios
  • Supports 2 to N JSON segments: default 2 input boxes, click "+" to dynamically add more source JSON, flexible for multi-source aggregation
  • Deep recursive merge: intelligently handles multi-level nested objects, resolves leaf conflicts by the specified strategy, preserving all valid fields
  • Flexible conflict resolution: top-level conflicts follow the selected strategy; nested object conflicts go deep; array conflicts differentiate via arrayConcat/arrayReplace
  • Unified formatted output: results are shown with 2-space indent for easy human review and direct copy to downstream tools
  • Real-time execution: click "Merge" right after pasting to get results; errors display specific JSON line numbers and error messages
  • Local processing for privacy: parsing, merging, and formatting all happen locally in the browser, no input sent to any server
  • Seamless downstream handoff: results can be one-click copied to JSON Formatter, Schema Validator, code generators, etc.

Code Examples

JavaScript deep merge with lodash.merge

javascript
// npm install lodash.merge
import merge from 'lodash.merge';

const a = { user: { name: 'Alice', age: 28 }, tags: ['admin'] };
const b = { user: { email: 'a@x.com', age: 29 }, tags: ['editor'] };

// Deep merge: nested objects merge recursively, leaf nodes take the later value
const deep = merge({}, a, b);
console.log(deep);
// => { user: { name: 'Alice', age: 29, email: 'a@x.com' }, tags: ['admin', 'editor'] }

// Shallow merge: top-level keys are replaced wholesale, no descent into nesting
const shallow = Object.assign({}, a, b);
console.log(shallow);
// => { user: { email: 'a@x.com', age: 29 }, tags: ['editor'] }

Python deep merge with mergedeep

python
# pip install mergedeep
from mergedeep import merge

a = {"user": {"name": "Alice", "age": 28}, "tags": ["admin"]}
b = {"user": {"email": "a@x.com", "age": 29}, "tags": ["editor"]}

# Deep merge
result = merge(a, b)
print(result)
# => {'user': {'name': 'Alice', 'age': 29, 'email': 'a@x.com'}, 'tags': ['admin', 'editor']}

# Note: mergedeep defaults to array concat; string/number overwrite.
# For array overwrite, add strategy='override'

CLI multi-JSON merge with jq -s

bash
# Merge multiple JSON arrays into one long array
jq -s 'add' a.json b.json c.json

# Recursively merge multiple JSON objects (jq 1.6+)
jq -s 'reduce .[] as $item ({}; . * $item)' a.json b.json

# Shallow merge: overlay b's top-level keys onto a
jq -s '.[0] * .[1]' a.json b.json

# Merge arrays and keep only deduplicated id fields
jq -s '[.[].items[]] | unique_by(.id)' a.json b.json

FAQ

Are JSON Merge and JSON Concatenation the same thing?

Not exactly. "Concatenation" usually means directly splicing strings without structure; "merge" means recursively combining multiple objects by JSON structure and handling key name conflicts. This tool refers to the latter — structured JSON merge.

How do I choose between Deep Merge and Shallow Merge?

Shallow merge: only handles top-level keys, same-named keys are replaced in their entirety, similar to `Object.assign` — simplest. Deep merge: recursively enters nested objects, merging at each leaf node — smarter. If your multiple JSONs add fields at different sub-paths (e.g. base.user.name and override.user.email), use deep merge. If you want an entire sub-object replaced at once, use shallow merge.

When merging arrays, is it by order or by index?

By default, this tool follows "concat" semantics: it combines multiple arrays into a long array preserving all element order. If your two arrays have the same length and you want index-wise overwrite, switch to "arrayReplace" and manually wrap the array in an object structure first.

How is the conflict winner decided when key names collide?

It's decided by input order: later JSON overwrites earlier same-named keys (full overwrite under Shallow / Array Replace strategies, only leaf overwrite under Deep Merge). If you want "earlier input wins", swap the input order.

Can it merge JSON arrays?

Yes. Two typical scenarios: ① Multiple JSONs are all arrays → use "arrayConcat" to merge into a long array; ② Multiple JSONs are objects, but one field is an array → use "arrayConcat" to merge the arrays, or use "arrayReplace" to keep the later input's value.

Can it merge more than 2 JSONs at once?

Yes. By default there are 2 input boxes; click "+" to dynamically add more. All inputs are merged top-to-bottom in order. Theoretically unlimited, but browser memory limits single segment size.

How is the key order determined after merging?

Deep merge: the first JSON's key order has priority; new keys from later JSONs are appended to the end of the corresponding level. Shallow merge: by input order — all keys from the first JSON appear first, new keys from later JSONs are appended at the top level; same-named keys keep the first's order unchanged.

Does the tool change field types?

No, it does not actively change types. If under Shallow / Array Replace strategy, the same-named keys in two JSONs are of different types (one object, one array), it follows "last input wins" and overwrites directly, without type conversion. Deep Merge only recurses when both sides are plain objects; in all other cases it overwrites.

Are null values preserved?

Yes. null is a legal JSON value; this tool treats null as a normal leaf value: under Shallow / Array Replace, a later null overwrites the prior value; under Deep Merge, a null is handled by the overwrite rule and not specially skipped.

Will the merge output any statistics?

Yes. The result area shows the number of JSON segments and the total key count, for quick verification; see the formatted output on the right for the full field list.

Will the tool upload my JSON to a server?

No. Parsing, merging, and formatting all happen locally in the browser, input and intermediate results are not sent to any server. Works offline, suitable for sensitive multi-source JSON (e.g. production environment configs, internal API responses).

What is the best order of use with JSON Formatter and Schema Validator?

Recommended chain: ① JSON Repair (clean illegal JSON) → ② This JSON Merge tool (multi-source merge) → ③ JSON Formatter (unify indent) → ④ JSON Schema Validation (verify final structure) → ⑤ Code generation (TypeScript / Java / Go etc.). Pick whichever steps you need.

Troubleshooting

Merge shows "Unexpected token" or "Invalid JSON"

Cause: at least one input box contains invalid JSON. Solution: first paste the failing JSON into the JSON Repair tool to clean (auto-handle trailing commas, single quotes, unquoted keys, etc.), then come back to this tool; or check whether you missed outer braces / brackets.

Some fields don't appear after merging

Cause: under Shallow / Array Replace strategy, same-named keys are wholly overwritten by later input; under Deep Merge, null-valued fields also overwrite the preceding object. Solution: switch the strategy to "Deep Merge" to check layer by layer; if confirmed it's a later null overwrite, remove the null field from the later JSON or replace with a placeholder.

Array got replaced instead of concatenated

Cause: the current strategy is "Shallow Merge" or "Array Replace". Solution: in the toolbar dropdown, switch to "Array Concat"; or manually combine the two arrays into one before merging.

Object turned into an array (or vice versa) after Deep Merge

Cause: the two JSONs have inconsistent types at the same path ("object vs array"); Deep Merge follows "last input wins" when types differ. Solution: unify the types on both sides (both as object or both as array), or switch to Shallow / Array Replace strategy to make semantics explicit.

Key order is messed up after merge

Cause: the second JSON's new keys are appended by insertion position after the first JSON; browsers / parsers auto-sort pure integer keys numerically. Solution: first run all input JSONs through the JSON Sort tool to unify key name order, then merge; or sort again before using the result.

Large files (10 MB+) cause the merge to freeze

Cause: parsing many large texts with JSON.parse at once takes a lot of memory. Solution: keep each input within 1-2 MB; for huge files use Node.js (lodash.merge) or Python (mergedeep) scripts locally; use this tool for small verification afterwards.

Glossary

JSON Merge
Operation of combining two or more JSON objects into a new one by specified rules. The core challenge is the strategy for resolving key name conflicts.
Deep Merge
Strategy that recursively enters nested objects and merges at each leaf node; recurses only when both sides are plain objects, otherwise falls back to overwrite.
Shallow Merge
Strategy that only merges top-level keys and replaces same-named keys in their entirety; equivalent in JS to `Object.assign({}, a, b)`.
Array Concat
One of the array merge strategies: combines multiple arrays into a long array preserving all element order; often used for API response aggregation.
Array Replace
One of the array merge strategies: same-named arrays are replaced in their entirety with the later input; often used for config override.
Object.assign
Built-in JavaScript method that shallow-copies all enumerable own properties from one or more source objects to a target object; the de-facto standard implementation of shallow merge.
lodash.merge
Deep merge function provided by the Lodash library; the most common deep merge implementation in the Node.js ecosystem; arrays are concatenated, not overwritten.
mergedeep (Python)
Deep merge library in the Python ecosystem (pip install mergedeep); supports a strategy parameter to control array concat vs replace behavior.
jq -s 'add'
jq command that sums multiple JSON arrays into one; merging multiple JSON objects requires `reduce .[] as $item ({}; . * $item)`.
BFF (Backend for Frontend)
Aggregation layer in microservices architecture located between front-end and back-end services; often needs to merge JSON responses from multiple services into a unified response — a classic JSON merge scenario.

4 JSON Merge Strategies Compared

StrategyScopeArray handlingTypical scenario
Deep MergeRecurses all nested levelsBy selected arrayConcat/arrayReplaceMulti-env config layering, i18n dictionary merge
Shallow MergeOnly merges top levelFull overwriteSimple Object.assign-style replacement
Array ConcatTop levelConcatenated into new arrayPaginated API aggregation, mock data merge
Array ReplaceTop levelLast input winsFeature Flag config override

Common JSON Merge Implementations Compared

Implementation / libraryLanguageDefault behaviorNotes
Object.assignJavaScriptShallow mergeES2015 standard lib; after ES2017 you can use `Object.assign({}, a, b)`
{ ...a, ...b }JavaScriptShallow mergeSpread operator; more concise syntax
lodash.mergeJavaScriptDeep mergeArrays concat (no overwrite); npm install lodash.merge
mergedeepPythonDeep mergestrategy='override' to change array concat to replace
deepmerge (Python)PythonDeep mergeAnother popular implementation; pip install deepmerge
jq -s 'add'ShellArray sumObject merge needs `reduce .[] as $i ({}; . * $i)`

Authoritative References