$$flatten
Flattens an object into a flat dot seperated list of entries
Usage​
{
"$$flatten": /* any object */,
"target": null /* object */,
"prefix": "" /* string */,
"array_prefix": "$" /* string */
}
"$$flatten([target],[prefix],[array_prefix]):{input}"
note
Concrete values in the usage example are default values.
Returns​
object
Arguments​
Argument | Type | Values | Required / Default Value | Description |
---|---|---|---|---|
Primary | object | Yes | any object | |
target | object | null | A target to merge into | |
prefix | string | "" | A prefix to add to the base | |
array_prefix | string | "$" | Sets how array elements indices should be prefixed (If not set, elements will be prefixed like $\{index} ). - Set to "#null" to not flatten arrays. |
Examples​
Input
Definition
Output
{
"value": "bbb"
}
{
"$$flatten": {
"a": {
"a1": 123,
"a2": [
1,
2,
3,
{
"c": true
}
]
},
"b": "$.value"
},
"array_prefix": "\\$"
}
{
"a.a1": 123,
"a.a2.$0": 1,
"a.a2.$1": 2,
"a.a2.$2": 3,
"a.a2.$3.c": true,
"b": "bbb"
}
{
"value": "bbb"
}
{
"$$flatten": {
"a": {
"a1": 123,
"a2": [
1,
2,
3,
{
"c": true
}
]
},
"b": "$.value"
},
"prefix": "xxx",
"array_prefix": ""
}
{
"xxx.a.a1": 123,
"xxx.a.a2.0": 1,
"xxx.a.a2.1": 2,
"xxx.a.a2.2": 3,
"xxx.a.a2.3.c": true,
"xxx.b": "bbb"
}
{
"value": "bbb"
}
{
"$$flatten": {
"a": {
"a1": 123,
"a2": [
1,
2,
3,
{
"c": true
}
]
},
"b": "$.value"
},
"prefix": "xxx",
"array_prefix": "#null"
}
{
"xxx.a.a1": 123,
"xxx.a.a2": [
1,
2,
3,
{
"c": true
}
],
"xxx.b": "bbb"
}
{
"a1": 123,
"a2": [
1,
2
]
}
"$$flatten(,x,''):$"
{
"x.a1": 123,
"x.a2.0": 1,
"x.a2.1": 2
}
{
"a1": 123,
"a2": [
1,
2
]
}
"$$flatten(,x,'#null'):$"
{
"x.a1": 123,
"x.a2": [
1,
2
]
}