# snakecase-keys

> Convert an object's keys to snake case

Latest version **9.0.2** (published 2025-07-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install snakecase-keys
pnpm add snakecase-keys
yarn add snakecase-keys
bun add snakecase-keys
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 9.0.2 |
| Published | 2025-07-11 |
| First published | 2015-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 3 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 196 |
| Author | Ben Drucker |
| Maintainers | bendrucker |
| Keywords | snake, case, camel, keys, object |

## Links

- npm: https://www.npmjs.com/package/snakecase-keys
- Repository: https://github.com/bendrucker/snakecase-keys
- Homepage: https://github.com/bendrucker/snakecase-keys#readme
- Issues: https://github.com/bendrucker/snakecase-keys/issues
- npm.io page: https://npm.io/package/snakecase-keys

## Dependencies (3)

- [map-obj](https://npm.io/package/map-obj.md) ^5.0.2
- [type-fest](https://npm.io/package/type-fest.md) ^4.15.0
- [change-case](https://npm.io/package/change-case.md) ^5.4.4

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 9.0.2 (latest) — 2025-07-11
- 9.0.1 — 2025-07-07
- 9.0.0 — 2025-07-03
- 8.1.0 — 2025-07-03
- 8.0.1 — 2024-05-13
- 8.0.0 — 2024-04-09
- 7.0.1 — 2024-04-09
- 7.0.0 — 2024-03-26
- 6.0.0 — 2024-01-17
- 5.5.0 — 2023-10-19
- 5.4.7 — 2023-09-20
- 5.4.6 — 2023-06-22
- 5.4.5 — 2023-01-30
- 5.4.4 — 2022-08-29
- 5.4.3 — 2022-08-28
- … 24 more at https://npm.io/package/snakecase-keys/versions

## README

# snakecase-keys [![tests](https://github.com/bendrucker/snakecase-keys/workflows/tests/badge.svg?branch=main)](https://github.com/bendrucker/snakecase-keys/actions?query=workflow%3Atests+branch%3Amain)

> Convert an object's keys to snake case


## Install

```
npm install snakecase-keys
```


## Usage

```js
import snakecaseKeys from 'snakecase-keys'

snakecaseKeys({ fooBar: 'baz' })
//=> { foo_bar: 'baz' }

snakecaseKeys({ 'foo-bar': true, nested: { fooBaz: 'bar' } })
//=> { foo_bar: true, nested: { foo_baz: 'bar' } }
```

## API

#### `snakecaseKeys(obj, options)` -> `object`

##### obj

*Required*  
Type: `object | Array<object>`

A plain object or array of plain objects to transform into snake case (keys only).

##### options

*Optional*  
Type: `object`

###### deep

Type: `boolean`  
Default: `true`

Enables snake-casing of keys in nested objects.

###### exclude

Type: `Array<string | RegExp>`  
Default: `[]`

An array of strings or regular expressions matching keys that will be excluded from snake-casing.

###### `shouldRecurse(key, val)` -> `boolean`

*Optional*  
Type: `function`

A function that determines if `val` should be recursed.

Requires `deep: true`.

###### parsingOptions

Type: `object`  
Default: `{}`

Options object passed to the built-in `snakeCase` function from `change-case`. Available options include:

- `split`: Custom function to split strings into words
- `locale`: Locale for case conversion
- `separateNumbers`: Whether to separate numbers (deprecated, use `splitSeparateNumbers`)
- `delimiter`: Custom delimiter between words
- `prefixCharacters`: Characters to preserve at start
- `suffixCharacters`: Characters to preserve at end

See [`change-case`](https://github.com/blakeembrey/change-case) for full documentation.

###### snakeCase

*Optional*
Type: `(key: string) => string`

Custom function to convert a key to snake case. Use this to fully override the default behavior of the library and convert keys according to your own conventions. When provided, the return type will be a generic `Record<string, unknown>`, since specific keys cannot be inferred from the custom function.

## Related

* [camelcase-keys](https://github.com/sindresorhus/camelcase-keys)
* [kebabcase-keys](https://github.com/mattiloh/kebabcase-keys)

## License

MIT © [Ben Drucker](http://bendrucker.me)

---
_Source: https://npm.io/package/snakecase-keys · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
