Home > @idealeap/pipeline > mergeJSONSafely
mergeJSONSafely() function
Merges two JSON objects safely by checking for key conflicts. If a key exists in both obj1 and obj2, it will throw an error.
Signature:
typescript
export declare function mergeJSONSafely(obj1: object, obj2: object): object;export declare function mergeJSONSafely(obj1: object, obj2: object): object;Parameters
| Parameter | Type | Description |
|---|---|---|
| obj1 | object | The first object to merge. |
| obj2 | object | The second object to merge. |
Returns:
object
A merged object containing properties from both obj1 and obj2.
Exceptions
{Error} Throws an error if a key exists in both obj1 and obj2.
Example
const objA = { a: 1, b: 2 }; const objB = { c: 3 }; mergeJSONSafely(objA, objB); // Returns { a: 1, b: 2, c: 3 }