Sign up for our newsletter and receive a free copy of our book .NET Web Application Logging Essentials
"What a great idea, ELMAH (Error Logging) for .NET in the cloud."
Free online JSON merger tool
Merging JSON files is a common task when combining configuration files, aggregating API responses, or patching a base object with environment-specific overrides. This free JSON merger tool lets you paste two JSON objects and instantly produce a single merged result — entirely in your browser, with no data sent to any server.
The merger performs a deep merge: nested objects are merged recursively rather than replaced. If the same key exists in both objects, the value from the second object wins. Arrays are replaced wholesale by the second object's value.
For example, merging these two objects:
// JSON 1
{
"server": { "host": "localhost", "port": 8080 },
"debug": true
}
// JSON 2
{
"server": { "port": 9090, "timeout": 30 },
"debug": false
}
Produces the following result:
{
"server": { "host": "localhost", "port": 9090, "timeout": 30 },
"debug": false
}
Notice that server.host is preserved from the first object while server.port is overridden by the second, and server.timeout is added from the second object.
A shallow merge (like JavaScript's Object.assign or the spread operator { ...a, ...b }) replaces any top-level key entirely with the value from the second object — including nested objects. This means a nested object in the first input is completely discarded if the second input has the same key at the top level.
A deep merge recurses into nested objects so that only individual leaf values are overridden. This is the behavior you typically want when combining configuration files, such as an appsettings.json base with an environment-specific override file.
In JavaScript, a shallow merge looks like this:
const merged = { ...base, ...overrides };
A deep merge requires a recursive function or a library like lodash:
import merge from 'lodash/merge';
const merged = merge({}, base, overrides);
In C#, Newtonsoft.Json provides built-in support for deep merging JSON objects:
var base = JObject.Parse(json1);
var overrides = JObject.Parse(json2);
base.Merge(overrides, new JsonMergeSettings
{
MergeArrayHandling = MergeArrayHandling.Union
});
System.Text.Json does not have a built-in merge method, but the JsonNode API available from .NET 6 makes it straightforward to write one:
using System.Text.Json;
using System.Text.Json.Nodes;
static JsonObject DeepMerge(JsonObject target, JsonObject source)
{
var result = JsonNode.Parse(target.ToJsonString())!.AsObject();
foreach (var property in source)
{
if (property.Value is JsonObject sourceObj &&
result[property.Key] is JsonObject targetObj)
{
result[property.Key] = DeepMerge(targetObj, sourceObj);
}
else
{
result[property.Key] = property.Value?.DeepClone();
}
}
return result;
}
var base = JsonNode.Parse(json1)!.AsObject();
var overrides = JsonNode.Parse(json2)!.AsObject();
var merged = DeepMerge(base, overrides);
Console.WriteLine(merged.ToJsonString(new JsonSerializerOptions { WriteIndented = true }));
We monitor your websites for crashes and availability. This helps you get an overview of the quality of your applications and to spot trends in your releases.
We notify you when errors starts happening using Slack, Microsoft Teams, mail or other forms of communication to help you react to errors before your users do.
We help you fix bugs quickly by combining error diagnostic information with innovative quick fixes and answers from Stack Overflow and social media.