hughsk / flat

:steam_locomotive: Flatten/unflatten nested Javascript objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Who is down for a minDepth option?

sunknudsen opened this issue · comments

This would complement maxDepth in a coherent way.

minDepth

Number of nested objects to skip before flattening others.

var flatten = require('flat')

flatten({
    key1: {
        keyA: 'valueI'
    },
    key2: {
        keyB: 'valueII'
    },
    key3: { a: { b: { c: 2 } } }
}, { minDepth: 1 })

// {
//   key1: { keyA: 'valueI' },
//   key2: { keyB: 'valueII' },
//   key3: { a: { 'b.c': 2 } }
// }

Would love to see this option as well.

commented

I'm looking for this option as well. I intend to convert my data to csv, and need to keep first level as headers, but the default flatten everything using the index 0,data 1.data ... etc