# zod-package-json

> Zod schema for the package.json file format

Latest version **2.1.0** (published 2025-08-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install zod-package-json
pnpm add zod-package-json
yarn add zod-package-json
bun add zod-package-json
```

## Health

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

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

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2025-08-26 |
| First published | 2024-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 45.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Edoardo Scibona |
| Maintainers | velut |
| Keywords | zod, schema, package, json, typescript, npm |

## Links

- npm: https://www.npmjs.com/package/zod-package-json
- Repository: https://github.com/velut/zod-package-json
- Homepage: https://github.com/velut/zod-package-json#readme
- Issues: https://github.com/velut/zod-package-json/issues
- npm.io page: https://npm.io/package/zod-package-json

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.1.0 (latest) — 2025-08-26
- 2.0.0-0 (next) — 2025-07-30
- 2.0.0 — 2025-08-01
- 1.2.0 — 2025-06-16
- 1.1.0 — 2025-01-20
- 1.1.0-0 — 2025-01-20
- 1.0.3 — 2024-06-11
- 1.0.2 — 2024-04-23
- 1.0.1 — 2024-04-20
- 1.0.0 — 2024-04-11

## README

# zod-package-json

[![Build status](https://img.shields.io/github/actions/workflow/status/velut/zod-package-json/main.yml?branch=main)](https://github.com/velut/zod-package-json/actions?query=workflow%3ACI)
[![Coverage](https://img.shields.io/codecov/c/gh/velut/zod-package-json)](https://codecov.io/gh/velut/zod-package-json)
[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/zod-package-json)
![Language](https://img.shields.io/github/languages/top/velut/zod-package-json)
[![npm](https://img.shields.io/npm/v/zod-package-json)](https://www.npmjs.com/package/zod-package-json)
[![License](https://img.shields.io/github/license/velut/zod-package-json)](https://github.com/velut/zod-package-json/blob/main/LICENSE)

[Zod 4](https://zod.dev/) schema for the [`package.json`](https://docs.npmjs.com/cli/v11/configuring-npm/package-json) file format.

This package exports a [Zod](https://zod.dev/packages/zod) and a [Zod mini](https://zod.dev/packages/mini) schema (and the inferred TypeScript type) named `PackageJson`
that can parse most well-formed `package.json` files.

The schema includes all currently supported properties listed in the
[npm docs](https://docs.npmjs.com/cli/v11/configuring-npm/package-json)
as well as additional well-known properties specific to TypeScript and Node.js.

The schema also preserves unknown properties, which can be accessed
by indexing the parsed data with the desired string keys.

The schema only validates the known properties against their expected type
but does not do any additional normalization such as merging similar properties.
If necessary, that can be done by extending the schema with Zod methods such as
`.transform()` or `.refine()`.

## Useful resources

- [**Explore the API on jsDocs.io**](https://www.jsdocs.io/package/zod-package-json)
- View package contents on [**unpkg**](https://unpkg.com/zod-package-json/)
- View repository on [**GitHub**](https://github.com/velut/zod-package-json)
- Read the changelog on [**GitHub**](https://github.com/velut/zod-package-json/blob/main/CHANGELOG.md)

## Install

> [!NOTE]  
> Make sure you have Zod v4 installed in your application to use this package.

Using `npm`:

```
npm add zod zod-package-json
```

Using `yarn`:

```
yarn add zod zod-package-json
```

Using `pnpm`:

```
pnpm add zod zod-package-json
```

Using `bun`:

```
bun add zod zod-package-json
```

## Usage examples

To use the classic Zod schema:

```typescript
import { PackageJson } from "zod-package-json";

// Parse data from a `package.json` file.
const packageJson = PackageJson.parse({
	name: "foo",
	version: "1.0.0",
	unknownProp: "who knows",
});

// Access a known property.
packageJson.name; // "foo"

// Access an unknown property.
packageJson["unknownProp"]; // "who knows"
```

To use the [Zod mini](https://zod.dev/packages/mini) schema:

```typescript
import { PackageJson } from "zod-package-json/mini";

// Parse data from a `package.json` file.
const packageJson = PackageJson.parse({
	name: "foo",
	version: "1.0.0",
	unknownProp: "who knows",
});

// Access a known property.
packageJson.name; // "foo"

// Access an unknown property.
packageJson["unknownProp"]; // "who knows"
```

## License

```
MIT
```

Copyright (c) 2025 Edoardo Scibona

See [LICENSE](./LICENSE) file.

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