Détail du package

zod-package-json

velut203.6kMIT2.1.0

Zod schema for the package.json file format

zod, schema, package, json

readme

zod-package-json

Build status Coverage jsDocs.io Language npm License

Zod 4 schema for the package.json file format.

This package exports a Zod and a Zod 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 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

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:

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 schema:

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 file.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

  • None

2.0.0 - 2025-08-01

Added

  • Added Zod mini schema available at the zod-package-json/mini subpath (Thanks @43081j)
  • Added libc property to PackageJson
  • Added devEngines property to PackageJson

Changed

  • Upgraded to Zod 4 (Thanks @43081j)

1.2.0 - 2025-06-16

Changed

  • Upgraded dependencies

1.1.0 - 2025-01-20

Changed

  • Upgraded dependencies

1.0.3 - 2024-06-12

Changed

1.0.2 - 2024-04-23

Changed

  • Upgrade dependencies: zod@3.23.3

1.0.1 - 2024-04-21

Fixed

  • Add booleans to the browser object values (a1de691)
  • Widen config object values to unknown (95224f9)