Registry / serialization / stringify-keys

stringify-keys

JSON →
library3.0.0jsnpmunverified

Build an array of key paths from a nested object, with support for custom separators, escaping, and optional inclusion of values. Version 3.0.0 removes redundant parent keys (e.g., 'a' is omitted when 'a.b' exists) and adds array traversal support. Maintenance-mode library with low release cadence (last major update in 2018). Differentiated by lightweight size, simple API, and escape handling for keys containing dots.

npm install stringify-keys
INSTALL
IMPORT
SIG · STRINGIFY-KEYS
S
stringify-keys
serializationjavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (stringify)
import stringify from 'stringify-keys'
const stringify = require('stringify-keys')
Default import is the function. CJS require also works but ESM is preferred.
type definitions
import type { Options } from 'stringify-keys'
TypeScript users can import Options interface for type safety. Not exported as a value.
CommonJS require
const stringify = require('stringify-keys')
const { stringify } = require('stringify-keys')
The module exports a single function, not an object with a named export.

Demonstrates basic usage, values output, custom separator, and custom escape function.

import stringify from 'stringify-keys'; const obj = { a: 'a', b: { c: { d: { e: 'f' } } }, 'a.b.c': { d: 'e' }, arr: [{ x: 1 }, { y: 2 }] }; // Basic usage: get key paths as array console.log(stringify(obj)); // Output: ['a', 'b.c.d.e', 'a\\.b\\.c.d', 'arr.0.x', 'arr.1.y'] // Include values in result object console.log(stringify(obj, { values: true })); // Output: { a: 'a', 'b.c.d.e': 'f', 'a\\.b\\.c.d': 'e', 'arr.0.x': 1, 'arr.1.y': 2 } // Custom separator console.log(stringify(obj, { separator: '/' })); // Output: ['a', 'b/c/d/e', 'a.b.c/d', 'arr/0/x', 'arr/1/y'] // Custom escape function const escapeFn = (str) => str.split('.').join('_'); console.log(stringify({ 'a.b': 'c' }, { escape: escapeFn })); // Output: ['a_b']
Debug
Known issues
breakingIn v3.0.0, redundant parent keys are no longer included. For example, stringify({a: {b: 'c'}}) returns ['a.b'] instead of ['a', 'a.b'].
fix
Update any code that expects parent keys to be present. Use { values: true } with paths including parents if needed.
affects: >=3.0.0
gotchaKeys containing dots are automatically escaped with backslashes by default (e.g., 'a.b' becomes 'a\\.b'). This can break naive string splitting.
fix
Use the escape option or manually handle backslash-escaping when processing paths.
affects: >=1.0.0
gotchaArray indices are included as numeric path parts (e.g., 'arr.0.x'). This may not be expected if you want to skip array traversal.
fix
Filter out array indices from results if needed, or avoid passing arrays directly.
affects: >=2.0.0
deprecatedThe package is in maintenance mode with no recent updates. It may not receive fixes for future Node.js versions.
fix
Consider migrating to alternatives like dot-prop or object-path if active development is needed.
affects: *
Errors
Common errors & fixes
TypeError: stringify is not a function
Wrong import: using destructured import { stringify } instead of default import.
fix
Use 'import stringify from 'stringify-keys'' or 'const stringify = require('stringify-keys')'.
Cannot find module 'stringify-keys'
Package not installed or typo in package name.
fix
Run 'npm install stringify-keys' and ensure the import path is exactly 'stringify-keys'.
Unexpected token in JSON at position X
Passing a JSON string instead of a JavaScript object.
fix
Parse the JSON string first: 'stringify(JSON.parse(str))'.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
stringify-keys — npm install stringify-keys · libregistry