JSON.Merge
----------

Merges multiple JSON objects or arrays.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [JSON](component_JSON.md) | [14.2](newinversion142.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "JSON.Merge"; json1; json2... ) 

**MBS**( **"JSON.Merge";** /\* Merges multiple JSON objects or arrays. \*/  
**$json1**; /\* A JSON text or reference.e.g. {"key": "value"} \*/   
**$json2...**) /\* A JSON text or reference.e.g. {"key2": "value2"} \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| json1 | A JSON text or reference. | {"key": "value"} |
| json2... | A JSON text or reference. | {"key2": "value2"} |

### Result

Returns JSON or error.

### Description

Merges multiple JSON objects or arrays.  
You can pass more than 2 parameters if you need to merge multiple objects or arrays.  
For arrays, we check if the value is already there and if not, we add it.  
For objects, we check the values for each key. If it doesn't exist, we copy it over. If it exists, we check arrays and objects again, but other values just get replaced.  
  
This function takes variable number of parameters. Pass as much parameters as needed separated by the semicolon in FileMaker.  
Please repeat json2 parameter as often as you need.  
### Examples

Merge two arrays:

 MBS ("JSON.Merge"; "\[1,2,3\]"; "\[3,4,5\]")  
<small>  
Example result:   
\[1 , 2 , 3 , 4 , 5 \] </small>Merge two objects:

 MBS ("JSON.Merge"; "{\\"a\\":1}"; "{\\"b\\":2}")  
<small>  
Example result:   
{ "a" : 1 , "b" : 2 } </small>Merge two arrays with replacing a value:

 MBS ("JSON.Merge"; "{\\"a\\":1, \\"c\\":3}"; "{\\"b\\":2, \\"c\\":4}")  
<small>  
Example result:   
{ "a" : 1 , "c" : 4 , "b" : 2 } </small>Merge two objects with array:

 MBS ("JSON.Merge"; "{\\"a\\":\[1,2\], \\"c\\":3}"; "{\\"a\\":\[3,4\], \\"b\\":2, \\"c\\":4}")  
<small>  
Example result:   
{ "a" : \[1 , 2 , 3 , 4 \], "c" : 4 , "b" : 2 } </small>Merge two object with object:

 MBS ("JSON.Merge"; "{\\"a\\":{\\"a\\":1}, \\"c\\":3}"; "{\\"a\\":{\\"b\\":2}, \\"b\\":2")  
<small>  
Example result:   
{ "a" : { "a" : 1 , "b" : 2 }, "c" : 3 , "b" : 2 } </small>Merge four arrays:

 MBS ("JSON.Merge"; "\[1,2,3\]"; "\[3,4,5\]"; "\[6,7\]"; "\[7,9\]")  
<small>  
Example result:   
\[1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 \] </small>### See also

- [JSON.MergePatch.ApplyPatch](JSONMergePatchApplyPatch.md)
- [JSON.MergePatch.FromDiff](JSONMergePatchFromDiff.md)

### Release notes

- **Version 14.2**
    - Added [JSON.Merge](https://www.mbsplugins.eu/JSONMerge.shtml) function.
- **Version 14.0**
    - Added [JSON.JSONPatch.ApplyPatch](https://www.mbsplugins.eu/JSONJSONPatchApplyPatch.shtml), [JSON.JSONPatch.FromDiff](https://www.mbsplugins.eu/JSONJSONPatchFromDiff.shtml), [JSON.MergePatch.ApplyPatch](https://www.mbsplugins.eu/JSONMergePatchApplyPatch.shtml) and [JSON.MergePatch.FromDiff](https://www.mbsplugins.eu/JSONMergePatchFromDiff.shtml) functions.

### Blog Entries

- [Neues MBS Plugin 14.2 für Claris FileMaker](https://www.mbsplugins.de/archive/2024-05-14/Neues_MBS_Plugin_142_für_Clar/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin 14.2 for Claris FileMaker](https://www.mbsplugins.de/archive/2024-05-14/MBS_Plugin_142_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 14.2pr1](https://www.mbsplugins.de/archive/2024-04-02/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 19th March 2024 , last changed 19th March 2024

  
[JSON.List](JSONList.md) - [JSON.MergePatch.ApplyPatch](JSONMergePatchApplyPatch.md)

[HTML Version](JSONMerge.shtml)