flatulence
Flatten objects and arrays into non-nested objects and arrays. A flattened object consists of key paths pointing to primitive values. Paths are lodash-compatible so they can be used with _.set() and _.get().
Unflatten flattened objects and make them regular, nested JS objects again.
const flatulence = // Create a flat objectconst flattened = flatulence// { // a: 1, // 'b.c': 1, // 'b.d[0]': 1, // 'b.d[1]': 2, // 'b.d[2]': 3 // } // Optionally you can decide to keep empty arrays and objectsconst flattened = flflatten//// { // name: 'Mega Group 2',// loginId: 'admin_mega_merchant_2',// description: 'again, some description here',// merchantUsers: [],// map: {} // } // Create a flat object and provide a prefix to each keyvar flattened2 = flatulence//{ // 'my.prefix.key.a': 1,// 'my.prefix.key.b.c': 1,// 'my.prefix.key.b.d[0]': 1,// 'my.prefix.key.b.d[1]': 2,// 'my.prefix.key.b.d[2]': 3 //} const regular = flatulence// { a: 1, b: { c: 1, d: [ 1, 2, 3 ] } } // Only unflatten a sub objectconst b = flatulence// { c: 1, d: [ 1, 2, 3 ] } // Sub objects can even be arraysconst array = flatulence// [ 1, 2, 3 ]