A Zod v4 schema for validating full package.json files. Version 2.1.0 is latest, actively maintained, and requires Node >=20 and Zod ^4.0.0 as a peer dependency. It covers all npm-documented properties plus TypeScript- and Node-specific fields, preserves unknown properties, and exports both classic Zod and Zod mini schemas. Compared to ad‑hoc schemas, it is comprehensive, typed, and kept current with npm's docs.
npm install zod-package-jsonNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Parse a package.json file, access known and unknown properties, and handle parse errors with safeParse.
Use dynamic import() or switch to ESM (e.g., "type": "module" in your package.json).
Install zod@^4.0.0 alongside this package.
Use import { PackageJson } from 'zod-package-json' (or '/mini').Always import from a single entry point; do not mix import from root and from /mini in the same module.
Upgrade to v2 and ensure Zod v4 is installed. See CHANGELOG for migration details.
Convert to dynamic import: const { PackageJson } = await import('zod-package-json');Run npm install zod-package-json and ensure import is correct: import { PackageJson } from 'zod-package-json';Use typeof PackageJson._type to get the inferred type.
Use import { PackageJson } from 'zod-package-json';