flatten
The flatten
generator is a special generator that can be used to flatten
multiple objects or arrays into a single object or array. It has one parameter:
values
: The values to flatten. These can beobjects
,arrays
, orreferences
. These values must all return either objects or arrays, not both, otherwise an error will be thrown. If no values are provided, null will be returned.removeNull
: Whether to remove null values from the flattened object or array. If not specified, the default isfalse
. If set tofalse
and a null value is passed, an error will be thrown.
Example
Flatten two objects into one:
{
"type": "flatten",
"values": [
{
"type": "object",
"properties": {
"field1": "value1"
}
},
{
"type": "object",
"properties": {
"field2": "value2"
}
}
]
}
The result will look like this:
{
"field1": "value1",
"field2": "value2"
}