hughsk / flat

:steam_locomotive: Flatten/unflatten nested Javascript objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flatten starting at a specific level

amitrai99 opened this issue · comments

Hello,

First thanks for such a great library!

I was wondering if there is a config that will allow me to flatten my JSON file starting at a specific depth instead of always flattening from the root to leaf.

Use case:

Input:

flatten(
  {
    "foo": {
      "bar": {
        "a": 1,
        "b": 2,
        "c": 3
      }
    },
    "amaze": {
      "muppet": "wow",
      "haw": "maw"
    }
  }
);

Output:

{
  "foo": {
    "bar.a": 1,
    "bar.b": 2,
    "bar.c": 3,
  },
  "amaze": {
    "muppet": "wow",
    "haw": "maw"
  }
}

Looking at the current options it seems like this would be the opposite of maxDepth. Maybe a minDepth option.