# nested-obj

> Safely access and modify nested object properties using string paths

Latest version **0.2.3** (published 2026-07-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install nested-obj
pnpm add nested-obj
yarn add nested-obj
bun add nested-obj
```

## Health

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

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2026-07-31 |
| First published | 2024-03-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Constructive |
| Maintainers | pyramation |

## Links

- npm: https://www.npmjs.com/package/nested-obj
- Repository: https://github.com/constructive-io/dev-utils
- Issues: https://github.com/constructive-io/dev-utils/issues
- npm.io page: https://npm.io/package/nested-obj

## Recent versions

- 0.2.3 (latest) — 2026-07-31
- 0.2.2 — 2026-05-09
- 0.2.1 — 2026-01-29
- 0.2.0 — 2026-01-20
- 0.1.10 — 2025-12-27
- 0.1.9 — 2025-12-27
- 0.1.8 — 2025-12-27
- 0.1.7 — 2025-12-17
- 0.1.6 — 2025-12-14
- 0.1.5 — 2025-11-28
- 0.1.4 — 2025-11-26
- 0.1.3 — 2025-11-24
- 0.1.2 — 2025-11-24
- 0.1.1 — 2025-11-23
- 0.1.0 — 2025-11-23
- … 1 more at https://npm.io/package/nested-obj/versions

## README

# nested-obj

<p align="center" width="100%">
  <img src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" height="250">
</p>

<p align="center" width="100%">
  <a href="https://github.com/constructive-io/dev-utils/actions/workflows/ci.yml">
    <img height="20" src="https://github.com/constructive-io/dev-utils/actions/workflows/ci.yml/badge.svg" />
  </a>
  <a href="https://github.com/constructive-io/dev-utils/blob/main/LICENSE">
    <img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
  </a>
</p>

`nested-obj` is a simple and lightweight JavaScript utility library for safely accessing and modifying nested properties in objects using string paths.

## Features

- **Get**: Safely access nested properties in an object.
- **Set**: Set a value at a specific path in an object. Does not overwrite if the value is undefined.
- **Has**: Check if a specific path exists within an object.

## Installation

```bash
npm install nested-obj
```

## Usage

### Get

Retrieve a nested property value from an object.

```ts
import objectPath from 'nested-obj';

const obj = {
  user: {
    name: 'John Doe',
    address: {
      street: '123 Main St',
      city: 'Anytown'
    }
  }
};

const userName = objectPath.get(obj, 'user.name');
console.log(userName); // 'John Doe'
```

### Set

Set a value at a specific path in an object. If any part of the path does not exist, it will be created.

```ts
objectPath.set(obj, 'user.address.zip', '12345');
console.log(obj.user.address.zip); // '12345'
```

### Has

Check if a path exists within an object.

```ts
const hasCity = objectPath.has(obj, 'user.address.city');
console.log(hasCity); // true
```

## Running Tests

To run tests, execute the following command:

```sh
npm test
```

or for continuous

```sh
npm test:watch
```

---

## Development

### Setup

1. Clone the repository:

```bash
git clone https://github.com/constructive-io/dev-utils.git
```

2. Install dependencies:

```bash
cd dev-utils
pnpm install
pnpm build
```

3. Test the package of interest:

```bash
cd packages/<packagename>
pnpm test:watch
```

## Credits

**🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**

## Disclaimer

AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.

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