Deep Merge

v1.0.0
Merge
objectarray

Description

Deep Merge

Deep merge two JSON objects with configurable conflict resolution.

Description

This utility combines two JSON objects by merging their properties recursively. When both objects have the same key, you can choose how to resolve the conflict.

Configuration

FieldTypeDefaultDescription
Conflict StrategyenumdeepMergeHow to resolve when both objects have the same key
Array StrategyenumreplaceHow to handle array values during merge

Conflict Strategy Options

  • preferPrimary - Keep values from the primary (first) object
  • preferSecondary - Use values from the secondary (second) object
  • deepMerge - Recursively merge nested objects

Array Strategy Options

  • replace - Replace primary arrays with secondary arrays
  • concat - Concatenate arrays together
  • unique - Concatenate and remove duplicates

Examples

Basic Merge

Base Input:

{
  "name": "Alice",
  "age": 30
}

Merge Input:

{
  "email": "alice@example.com"
}

Config:

conflictStrategy: deepMerge
arrayStrategy: replace

Output:

{
  "name": "Alice",
  "age": 30,
  "email": "alice@example.com"
}

Deep Merge Nested Objects

Base Input:

{
  "user": {
    "name": "Alice",
    "settings": {
      "theme": "dark"
    }
  }
}

Merge Input:

{
  "user": {
    "settings": {
      "language": "en"
    }
  }
}

Config:

conflictStrategy: deepMerge
arrayStrategy: replace

Output:

{
  "user": {
    "name": "Alice",
    "settings": {
      "theme": "dark",
      "language": "en"
    }
  }
}

Configuration

NameTypeDefaultDescription
Conflict StrategyenumdeepMergeHow to resolve when both objects have the same key preferPrimary preferSecondary deepMerge
Array StrategyenumreplaceHow to handle array values during merge replace concat unique

Examples

AI Prompt
Deep merge these JSON inputs.
Base Input
1{
2 "name": "Alice",
3 "age": 30
4}
Merge Input
1{
2 "email": "alice@example.com"
3}
Config
Conflict Strategy
deepMerge
Array Strategy
replace
Output
1{
2 "name": "Alice",
3 "age": 30,
4 "email": "alice@example.com"
5}

API Usage

POST /api/v1/utilities/merge.deep-merge
Example:
curl -X POST https://your-domain.com/api/v1/utilities/merge.deep-merge \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"inputs":{"primary":{"name":"Alice","age":30},"secondary":{"email":"alice@example.com"}},"config":{"conflictStrategy":"deepMerge","arrayStrategy":"replace"}}'
Response
1{
2 "name": "Alice",
3 "age": 30,
4 "email": "alice@example.com"
5}