flat

Flattens nested JavaScript objects into dot-delimited keys and unflattens them back, with a bundled CLI.

Library
npm
v6.0.1
1,816stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
46/100Fair
Development Activity4
Maintenance20
Community60
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
61/100Good
Architecture72
Code Quality75
Innovation65
Learning Curve30

flat is a small, dependency-free JavaScript utility that converts nested objects into a single level of dot-delimited keys, and reverses the process to rebuild the original structure from those flat keys. It treats arrays, buffers, typed arrays, and other non-plain-object values as leaf values rather than descending into them, and exposes configurable options for delimiter choice, maximum recursion depth, key transformation, array-safety, and overwrite behavior on conflicting keys.

Beyond the programmatic flatten/unflatten exports, the package ships a flat CLI binary that reads a JSON file (or piped stdin) and prints its flattened form, making it useful for quick inspection of deeply nested config or API response payloads directly from the terminal.

What You Get

  • flatten() and unflatten() functions exported as ES modules with full TypeScript type definitions (index.d.ts)
  • A flat command-line tool for flattening JSON files or piped stdin from the terminal
  • Configurable delimiter, maxDepth, transformKey, safe, object, and overwrite options covering both flatten and unflatten directions
  • Built-in prototype-pollution protection in unflatten__proto__ keys are silently skipped

Common Use Cases

  • Converting nested JSON config into KEY.PATH=value pairs for environment-variable-style storage
  • Flattening two nested API responses before diffing them so property-level mismatches are readable
  • Rebuilding structured objects from flat key-value data pulled from a database row or CLI arguments
  • Quick command-line inspection of deeply nested JSON files without writing a parsing script

Under The Hood

Architecture The package is a single ESM module (index.js) exporting two pure functions, flatten and unflatten, built from small private helpers (step, addKeys, getkey, isEmpty, isBuffer) with no internal layering beyond that — there’s no class hierarchy or plugin system to reason about. The cli.js binary is a thin wrapper that reads a file path argument or newline-delimited stdin, parses it as JSON, calls flatten, and writes the result to stdout. Because there’s a single code path with no abstraction boundary, any change to the recursive step() walk in flatten or the delimiter-splitting loop in unflatten immediately affects every consumer and the CLI alike.

Tech Stack Plain JavaScript targeting Node.js 18+ (per engines), shipped as ESM-only ("type": "module") with zero runtime dependencies — the only dependency listed is the standard linter as a devDependency. There is no build or bundling step; the files in package.json’s files array (cli.js, index.js, index.d.ts) are published as-is. The CLI relies solely on Node’s built-in fs, path, and readline modules, and type support for TypeScript consumers comes from a hand-written index.d.ts rather than compiled-down TypeScript source.

Code Quality test/test.js uses Node’s built-in test runner (node --test) with assert.deepStrictEqual across primitives, multi-level nesting, custom delimiters, maxDepth, transformKey, buffers, typed arrays, arrays, prototype-pollution safety, and CLI invocation via child_process.exec — comprehensive coverage relative to the package’s small surface area. Linting is enforced via the standard zero-config ESLint preset as part of the test script, and a GitHub Actions workflow badge in the README indicates CI runs on every push. The core functions do not throw on malformed input — they pass unexpected shapes through silently — and there is no internal type-checking beyond the hand-authored .d.ts declarations (no TypeScript source to enforce types at compile time).

API Design The library’s value is a minimal, symmetrical API — flatten and unflatten mirror each other and share the same delimiter/transformKey semantics — with sensible defaults and enough escape hatches (delimiter, maxDepth, safe, object, overwrite, transformKey) to cover most real-world edge cases without configuration ceremony. Getting started requires a single import and a single function call with no setup. The underlying technique — flattening nested keys via delimiter-joined recursion — is a well-established pattern also implemented by several comparable npm packages, so the package’s strength is in API completeness and ergonomics rather than a novel algorithm.

Used by 7 apps in this directory

TypeScript
97%
AGPL 3.0

Bigcapital

Invoicing Finance

3,884

Self-hostable double-entry accounting platform with invoicing, inventory, multi-currency, and real-time financial reporting for small and medium businesses.

View details
91
Repo Health
77
Technical
61
Dependency
Built with
TypeScript97%
Updated yesterday
TypeScript
81%
Other

Directus

CMS · Low Code Platforms

37,783

Connect any SQL database and get instant REST and GraphQL APIs, a visual management Studio, and a native MCP server for AI agents — free for most organizations.

View details
92
Repo Health
82
Technical
76
Dependency
Built with
TypeScript81%
Vue18%
Updated 3 days ago
TypeScript
96%
MIT

HyperDX

Developer Tools · Analytics · Monitoring

9,873

Open source observability platform that unifies logs, traces, metrics, and session replays on ClickHouse — now the core of ClickStack.

View details
88
Repo Health
83
Technical
68
Dependency
Built with
TypeScript96%
Updated yesterday
TypeScript
92%
Other

n8n

Automation · No Code Platforms

203,555

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
66
Dependency
Built with
TypeScript92%
Updated today
TypeScript
99%
Other

NocoBase

No Code Platforms · Low Code Platforms

24,071

Open-source AI + no-code platform that lets coding agents and people collaborate to build business systems fast on proven infrastructure.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
TypeScript99%
Updated today
TypeScript
98%
Other

Novu

Developer Tools

39,870

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
64
Dependency
Built with
TypeScript98%
Updated yesterday
TypeScript
91%
AGPL 3.0

PeerTube

Social Media

15,316

A federated, ActivityPub-based video hosting platform built by Framasoft — self-hostable instances interconnect into a network with no vendor lock-in, P2P-assisted streaming, and no ads.

View details
95
Repo Health
75
Technical
70
Dependency
Built with
TypeScript91%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search