
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
A tiny (188B) utility to flatten an object with customizable glue
This module squashes a nested object (including its internal Arrays) so that the output is a flat object – AKA, it has a single level of depth. By default, the _ character is used to glue/join layers' keys together. This is customizable, of course.
Finally, any keys with nullish values (null and undefined) are not included in the return object.
$ npm install --save flat-obj
import flatObj from 'flat-obj';
flatObj({
a: 'hi',
b: {
a: null,
b: ['foo', '', null, 'bar'],
d: 'hello',
e: {
a: 'yo',
b: undefined,
c: 'sup',
d: 0,
f: [
{ foo: 123, bar: 123 },
{ foo: 465, bar: 456 },
]
}
},
c: 'world'
});
// {
// a: 'hi',
// b_b_0: 'foo',
// b_b_1: '',
// b_b_3: 'bar',
// b_d: 'hello',
// b_e_a: 'yo',
// b_e_c: 'sup',
// b_e_d: 0,
// b_e_f_0_foo: 123,
// b_e_f_0_bar: 123,
// b_e_f_1_foo: 465,
// b_e_f_1_bar: 456,
// c: 'world'
// }
Note:
nullandundefinedvalues are purged.
Returns: Object
Returns a new object with a single level of depth.
Important: An object is always returned despite
inputtype.
Type: Object|Array
The object to flatten.
Type: String
Default: _
A string used to join parent key names to nested child key names.
const foo = { bar: 123 };
flatObj({ foo }); //=> { foo_bar: 123 }
flatObj({ foo }, '.'); //=> { 'foo.bar': 123 }
Running on Node.js v10.13.0
Validation:
✔ flat
✔ flatten-object
✔ flat-obj@1.x
✔ flat-obj
Benchmark:
flat x 186,002 ops/sec ±1.28% (89 runs sampled)
flatten-object x 188,715 ops/sec ±0.22% (94 runs sampled)
flat-obj@1.x x 274,414 ops/sec ±1.03% (95 runs sampled)
flat-obj x 363,332 ops/sec ±0.57% (97 runs sampled)
MIT © Luke Edwards
FAQs
A tiny (188B) utility to flatten an object with customizable glue
The npm package flat-obj receives a total of 315 weekly downloads. As such, flat-obj popularity was classified as not popular.
We found that flat-obj demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.