flatten-object
Flatten object to simple key/value object with customized separator
Install
npm install --save obj-flat
Usage
Arguments
object(Object)
- The object to process.[options={}](object)
- The option object.[options.sort=false](boolean)
- Return key-sorted object or not, default is false
Returns
(Object)
- Returns new flattened object.
Sample
Flatten normal object
const flattenObject = const data = z: 1 x: 2 a: 3 b: 4const output = // {// a: 3,// b: 4,// x: 2,// z: 1// }
Flatten object with multiple levels nested properties
const flattenObject = const data = a: 1 b: b2: 4 b1: b12: 3 b11: 2 b3: b32: 6 b31: 5 b34: 8 b33: 7 b35: b352: 10 b351: 9 c: 11 12 13 const output = // {// 'a': 1// 'b.b1.b11': 2// 'b.b1.b12': 3// 'b.b2': 4// 'b.b3.0.b31': 5// 'b.b3.0.b32': 6// 'b.b3.1.b33': 7// 'b.b3.1.b34': 8// 'b.b3.1.b35.b351': 9// 'b.b3.1.b35.b352': 10// 'c.0': 11// 'c.1': 12// 'c.2': 13// }