Skip to main content

$$merge

Merge multiple objects into one. Allows deep merging and array concatenation.

Usage​

{ 
"$$merge": /* Array of objects to merge */,
"deep": false /* boolean */,
"arrays": false /* boolean */
}
"$$merge([deep],[arrays]):{input}"
note

Concrete values in the usage example are default values.

Returns​

The merged schema of all specified objects

Arguments​

ArgumentTypeValuesRequired / Default ValueDescription
PrimaryarrayYesArray of objects to merge
deepbooleanfalse/truefalseWhether to merge objects deeply
arraysbooleanfalse/truefalseWhether to concatenate arrays

Examples​

Input

Definition

Output

{
"a": "A"
}
{
"$$merge": [
"$",
{
"b": "B"
}
]
}
{
"a": "A",
"b": "B"
}
{
"a": "A",
"b": "B"
}
{
"$$merge": [
"$",
{
"b": "BB"
}
]
}
{
"a": "A",
"b": "BB"
}
{
"a": "A",
"b": "B"
}
{
"$$merge": [
"$",
{
"b": "#null"
}
]
}
{
"a": "A",
"b": null
}
{
"a": {
"aa": "AA"
},
"b": "B"
}
{
"$$merge": [
"$",
{
"a": {
"aaa": "AAA"
}
}
]
}
{
"a": {
"aaa": "AAA"
},
"b": "B"
}
{
"a": {
"aa": "AA"
},
"b": "B"
}
{
"$$merge": [
"$",
{
"a": {
"aaa": "AAA"
}
}
],
"deep": true
}
{
"a": {
"aa": "AA",
"aaa": "AAA"
},
"b": "B"
}
{
"a": {
"aa": "AA"
},
"c": [
1,
2
]
}
{
"$$merge": [
"$",
{
"a": {
"aaa": "AAA"
},
"c": [
3,
4
]
}
],
"deep": true,
"arrays": true
}
{
"a": {
"aa": "AA",
"aaa": "AAA"
},
"c": [
1,
2,
3,
4
]
}
{
"a": {
"aa": "AA"
},
"c": [
1,
2
]
}
{
"$$merge": [
"$",
{
"a": {
"aaa": "AAA"
},
"c": [
3,
4
]
}
],
"arrays": true
}
{
"a": {
"aaa": "AAA"
},
"c": [
1,
2,
3,
4
]
}