JSON Merge Tool
Merge two JSON objects or arrays with multiple strategies
JSON Merge Tool — what it does
Merge two JSON documents with a strategy you choose: a shallow object merge where top-level keys overwrite, a deep merge that recurses into nested objects, or array concatenation. The strategy is the whole decision — shallow replaces a nested object wholesale, deep combines it key by key.
Worked example
A base configuration (A) merged with an override (B) using the Deep object merge strategy.
Input — JSON A and JSON B
JSON A
{"app":"Daily Office Tools","limits":{"max_rows":1000,"max_files":10},"features":["csv","json"]}
JSON B
{"limits":{"max_rows":5000},"features":["xlsx"],"owner":"Ops team"}Output — deep merge
{
"app": "Daily Office Tools",
"limits": {
"max_rows": 5000,
"max_files": 10
},
"features": [
"csv",
"json",
"xlsx"
],
"owner": "Ops team"
}Inside limits only max_rows was overridden and max_files survived; the features arrays were concatenated. A Shallow object merge of the same input instead gives limits: {"max_rows": 5000} and features: ["xlsx"].
When this tool helps
- Layering an environment-specific configuration over a base configuration file.
- Combining two API responses into one document for a single downstream consumer.
- Appending one array of records onto another before processing them together.
How to use it
- Paste the first JSON document.
- Paste the second document.
- Choose shallow, deep or array concatenation.
- Process and copy the merged output.
Accuracy, limits, and good practice
- Deep merge is what configuration layering needs: a shallow merge replaces an entire nested settings block instead of overriding one field inside it.
- The second document wins on conflicts, which is what makes the override direction predictable — put the more specific data second.
- Arrays are replaced rather than merged element by element unless you choose concatenation; there is no reliable way to merge arrays by identity.
Frequently asked questions
What is the difference between shallow and deep?
Shallow overwrites top-level keys entirely. Deep recurses, so nested objects are combined field by field instead of replaced.
Which document takes priority?
The second one. Its values overwrite matching keys from the first.
Can I merge more than two documents?
Merge two, then merge the result with the third, and so on. The order determines the final precedence.
What happens to arrays in a deep merge?
They are concatenated, not replaced: features ["csv","json"] plus ["xlsx"] became all three in the example, duplicates included if both sides share values. Choose Shallow object merge if B's array should replace A's.
Can I mix an array and an object?
Concatenate arrays refuses with 'Both JSON values must be arrays.' A shallow merge accepts it but spreads the array's indexes as keys: [{"id":1}] merged with {"id":2} gives {"0":{"id":1},"id":2}, which is rarely what you want.
Related tools on this site
- CSV to Markdown Table — Convert a CSV file into a Markdown table
- JSON Key Renamer — Rename matching object keys recursively throughout JSON data
- CSV Column Statistics — Calculate numeric and uniqueness statistics for one column
Further reading: Cleaning a CSV export before you import it anywhere · CSV, JSON, YAML, XML and Markdown Tables: When Each Fits and How to Convert
Everything above runs inside this page. JSON Merge Tool needs no account, no upload, and no server round trip — close the tab and nothing is left behind.
JSON 合併工具能做什麼
以你選定的策略合併兩份 JSON:淺層合併讓最外層鍵覆蓋、深層合併遞迴進巢狀物件,或直接串接陣列。策略就是全部的決策——淺層會整塊換掉巢狀物件,深層則逐鍵合併。
實際範例
以 Deep object merge 策略把基礎設定(A)與覆寫設定(B)合併。
來源:JSON A 與 JSON B
JSON A
{"app":"Daily Office Tools","limits":{"max_rows":1000,"max_files":10},"features":["csv","json"]}
JSON B
{"limits":{"max_rows":5000},"features":["xlsx"],"owner":"Ops team"}深層合併後
{
"app": "Daily Office Tools",
"limits": {
"max_rows": 5000,
"max_files": 10
},
"features": [
"csv",
"json",
"xlsx"
],
"owner": "Ops team"
}limits 裡只有 max_rows 被覆寫,max_files 保留下來;features 兩個陣列被串接。同樣的來源改以 Shallow object merge 則得到 limits: {"max_rows": 5000} 與 features: ["xlsx"]。
什麼時候用得上
- 把環境專屬設定疊在基礎設定檔之上。
- 把兩份 API 回應併成一份,交給同一個下游使用。
- 把一組紀錄陣列接到另一組後面再一起處理。
使用步驟
- 貼上第一份 JSON 文件。
- 貼上第二份文件。
- 選擇淺層、深層或陣列串接。
- 執行處理並複製合併結果。
精確度、限制與實務建議
- 設定分層需要的是深層合併:淺層合併會把整個巢狀設定區塊換掉,而不是只覆蓋其中一個欄位。
- 衝突時以第二份為準,覆蓋方向因此可預測——請把較具體的資料放在第二份。
- 除非選擇串接,陣列是整個被取代而非逐元素合併;依身份合併陣列本來就沒有可靠做法。
常見問題
淺層與深層差在哪?
淺層直接覆蓋最外層鍵;深層會遞迴,巢狀物件是逐欄位合併而非整個取代。
哪一份優先?
第二份。它的值會覆蓋第一份中相符的鍵。
可以合併超過兩份嗎?
先合併兩份,再把結果與第三份合併,依此類推。順序決定最終優先權。
深層合併時陣列會怎樣?
會被串接而不是取代:範例裡 features 的 ["csv","json"] 加上 ["xlsx"] 變成三個都在,兩邊若有相同的值也會重複。希望 B 的陣列直接取代 A 的,就改選 Shallow object merge。
可以一邊陣列、一邊物件嗎?
Concatenate arrays 會拒絕並顯示 Both JSON values must be arrays.。淺層合併雖然接受,卻會把陣列的索引攤成鍵:[{"id":1}] 與 {"id":2} 合併得到 {"0":{"id":1},"id":2},很少是你要的。
本站相關工具
- CSV 轉 Markdown 表格 — 將 CSV 檔案轉成 Markdown 表格
- JSON 鍵名批量重新命名 — 在整份 JSON 中遞迴重新命名符合的物件鍵名
- CSV 欄位統計 — 計算指定欄位的數值與唯一值統計
延伸閱讀: 匯入之前先把 CSV 匯出檔清乾淨 · CSV、JSON、YAML、XML 與 Markdown 表格:各自適用的場合與轉換方法
以上步驟全部在這個頁面內完成,JSON 合併工具 不需要註冊、不上傳檔案、也不經過伺服器,關閉分頁後不會留下任何資料。