{"id":49842,"library":"zod-package-json","title":"zod-package-json","description":"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.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/velut/zod-package-json","tags":["javascript","zod","schema","package","json","typescript","npm"],"install":[{"cmd":"npm install zod-package-json","lang":"bash","label":"npm"},{"cmd":"yarn add zod-package-json","lang":"bash","label":"yarn"},{"cmd":"pnpm add zod-package-json","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency – Zod v4 is required at runtime for schema validation.","package":"zod","optional":false}],"imports":[{"note":"ESM-only since v2. CommonJS require() will fail with ERR_REQUIRE_ESM.","wrong":"const PackageJson = require('zod-package-json')","symbol":"PackageJson","correct":"import { PackageJson } from 'zod-package-json'"},{"note":"Use the /mini subpath import for the smaller Zod mini version. Types are built-in.","wrong":"import { PackageJson } from 'zod-package-json' // this gives the classic Zod schema, not mini","symbol":"PackageJson (mini schema)","correct":"import { PackageJson } from 'zod-package-json/mini'"},{"note":"The package does not export an explicit type alias for the inferred type. Use Zod's _type property.","wrong":"import { PackageJsonType } from 'zod-package-json'","symbol":"PackageJsonType (inferred type)","correct":"import { PackageJson } from 'zod-package-json';\ntype Pkg = typeof PackageJson._type;"},{"note":"This package does not re-export Zod. Always import zod separately: import { z } from 'zod'.","wrong":"import { z } from 'zod-package-json'","symbol":"z (Zod object used internally)","correct":"// Not exported directly; import zod separately"}],"quickstart":{"code":"import { PackageJson } from 'zod-package-json';\nimport { readFileSync } from 'fs';\n\nconst raw = JSON.parse(readFileSync('./package.json', 'utf-8'));\nconst pkg = PackageJson.parse(raw);\nconsole.log(pkg.name, pkg.version);\n\n// Access unknown properties via string index\nconst extra = pkg['myCustomField']; // unknown preserved\nconsole.log(extra);\n\n// Parse failure example\nconst result = PackageJson.safeParse({ version: 'not-semver' });\nif (!result.success) {\n  console.error(result.error.issues);\n}","lang":"typescript","description":"Parse a package.json file, access known and unknown properties, and handle parse errors with safeParse."},"warnings":[{"fix":"Use dynamic import() or switch to ESM (e.g., \"type\": \"module\" in your package.json).","message":"Version 2.x is ESM-only. require() will throw ERR_REQUIRE_ESM.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Install zod@^4.0.0 alongside this package.","message":"Peer dependency Zod v4 required; Zod v3 not supported.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use import { PackageJson } from 'zod-package-json' (or '/mini').","message":"The default export is not a function; must use named import { PackageJson }.","severity":"gotcha","affected_versions":"*"},{"fix":"Always import from a single entry point; do not mix import from root and from /mini in the same module.","message":"The /mini subpath import is separate from the main schema. Mixing them will not work.","severity":"gotcha","affected_versions":"*"},{"fix":"Upgrade to v2 and ensure Zod v4 is installed. See CHANGELOG for migration details.","message":"Version 1.x used Zod v3 and CommonJS. Version 2.x is a major rewrite.","severity":"deprecated","affected_versions":"<2.0.0"}],"env_vars":null,"search_vec":"'2.1.0':15 '20':23 '4.0.0':26 'activ':18 'ad':59 'classic':51 'compar':57 'comprehens':64 'cover':32 'current':68 'depend':30 'doc':72 'document':36 'export':49 'field':44 'file':13 'full':11 'hoc':60 'javascript':73 'json':4,77 'kept':67 'latest':17 'maintain':19 'mini':55 'node':22,42 'node-specif':41 'npm':35,70,79 'npm-document':34 'packag':3,76 'package.json':12 'peer':29 'plus':38 'preserv':45 'properti':37,47 'requir':21 'schema':8,56,61,75 'specif':43 'type':65 'typescript':39,78 'unknown':46 'v4':7 'valid':10 'version':14 'zod':2,6,25,52,54,74 'zod-package-json':1","created_at":"2026-06-07T17:03:53.026373+00:00","updated_at":"2026-06-07T17:03:53.026373+00:00","problems":[{"fix":"Convert to dynamic import: const { PackageJson } = await import('zod-package-json');","cause":"Using CommonJS require() with ESM-only v2 package.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module not supported."},{"fix":"Run npm install zod-package-json and ensure import is correct: import { PackageJson } from 'zod-package-json';","cause":"Package not installed or incorrect import path.","error":"Cannot find module 'zod-package-json'?"},{"fix":"Use typeof PackageJson._type to get the inferred type.","cause":"No explicit type export; uses Zod _type.","error":"The inferred type of 'PackageJson' cannot be referenced directly."},{"fix":"Use import { PackageJson } from 'zod-package-json';","cause":"Using default import instead of named import.","error":"TypeError: (0 , zod_package_json_1.PackageJson) is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/velut/zod-package-json#readme","github":"https://github.com/velut/zod-package-json","docs":null,"changelog":null,"pypi":null,"npm":"zod-package-json","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}