vrl 0.32.0

Vector Remap Language
Documentation
{
  "anchor": "flatten",
  "name": "flatten",
  "category": "Enumerate",
  "description": "Flattens the `value` into a single-level representation.",
  "arguments": [
    {
      "name": "value",
      "description": "The array or object to flatten.",
      "required": true,
      "type": [
        "object",
        "array"
      ]
    },
    {
      "name": "separator",
      "description": "The separator to join nested keys",
      "required": false,
      "type": [
        "string"
      ],
      "default": "."
    },
    {
      "name": "except",
      "description": "An array of key names to exclude from flattening at any depth.",
      "required": false,
      "type": [
        "array"
      ],
      "default": "[]"
    }
  ],
  "return": {
    "types": [
      "object",
      "array"
    ],
    "rules": [
      "The return type matches the `value` type."
    ]
  },
  "examples": [
    {
      "title": "Flatten array",
      "source": "flatten([1, [2, 3, 4], [5, [6, 7], 8], 9])",
      "return": [
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9
      ]
    },
    {
      "title": "Flatten object",
      "source": "flatten({\n    \"parent1\": {\n        \"child1\": 1,\n        \"child2\": 2\n    },\n    \"parent2\": {\n        \"child3\": 3\n    }\n})\n",
      "return": {
        "parent1.child1": 1,
        "parent1.child2": 2,
        "parent2.child3": 3
      }
    },
    {
      "title": "Flatten object with custom separator",
      "source": "flatten({ \"foo\": { \"bar\": true }}, \"_\")",
      "return": {
        "foo_bar": true
      }
    },
    {
      "title": "Flatten object with except",
      "source": "flatten({ \"parent\": { \"child\": 1 }, \"keep\": { \"nested\": 2 } }, except: [\"keep\"])",
      "return": {
        "keep": {
          "nested": 2
        },
        "parent.child": 1
      }
    }
  ],
  "pure": true
}