{"_id":"@peculiar/json-schema@3.0.0","bugs":{"url":"https://github.com/PeculiarVentures/json-schema/issues"},"dist":{"shasum":"d0f13578c23d4a57d9e130dd115c71247cdf8955","tarball":"http://registry-npm.ywwl.com/@peculiar/json-schema/download/@peculiar/json-schema-3.0.0.tgz","fileCount":37,"integrity":"sha512-G9dN0s7Znz2Uy1sGvTsiHYKoTYcoZyqUYj635F7R5pDh3uwunDBBH3Cf7+xZQYMRYrZJeBVuaZmf+Evkf0Zcuw==","signatures":[{"sig":"MEYCIQCKRV0I7fKJxwiA76bv3Nj4Ff0VIsflTUnvO/3jGwTggAIhAN2EDCyNXZLkA1g3NJdfBEpXuoliQGSbDHKnZveRklfc","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDOE4xretuBvehkV+oWAZ6q8Gt4ZgXIk9EI9SNphONiCAIhAMT9U8WXfLMqyvhNWVrK/6DH68MIuhr0UwjEfFubMrDB"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@peculiar%2fjson-schema@3.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":36002,"size":10228,"noattachment":false,"key":"/@peculiar/json-schema/-/@peculiar/json-schema-3.0.0.tgz"},"main":"./build/index.js","name":"@peculiar/json-schema","type":"module","types":"./build/index.d.ts","author":{"name":"PeculiarVentures, Inc"},"module":"./build/index.js","engines":{"node":"^20.19.0 || >=22.12.0"},"exports":{".":"./build/index.js","./package.json":"./package.json"},"gitHead":"154ad821e73970ae25f35eb9ee341b7c1fe8c84c","license":"MIT","scripts":{"lint":"oxlint","test":"vitest run","build":"tsdown","format":"oxfmt","prepack":"npm run build","coverage":"vitest run --coverage","lint:fix":"oxlint --fix","typecheck":"tsc --noEmit","format:check":"oxfmt --check"},"version":"3.0.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"a27c6648-2cb5-47c5-8055-533ac06ef0dd"}},"homepage":"https://github.com/PeculiarVentures/json-schema#readme","keywords":["json","stringify","serialize","parse","convert","decorator"],"repository":{"url":"git+https://github.com/PeculiarVentures/json-schema.git","type":"git"},"_npmVersion":"11.19.0","description":"Serialize, parse and validate JSON with TypeScript decorators","directories":{},"maintainers":[{"name":"rmhrisk","email":"ryan_hurst@hotmail.com"},{"name":"microshine","email":"microshine@mail.ru"},{"name":"yury.strozhevsky","email":"yury@strozhevsky.com"},{"name":"peculiarventures","email":"info@peculiarventures.com"},{"name":"apilguk","email":"apilguk@gmail.com"},{"name":"donskov","email":"donskovdmitriyv@gmail.com"},{"name":"worldthirteen","email":"mihailzachepilo@gmail.com"}],"sideEffects":false,"_nodeVersion":"24.21.0","contributors":[{"name":"Ryan Hurst","email":"rmh@unmitigatedrisk.com"},{"name":"Miroshin Stepan","email":"microshine@mail.ru"}],"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"oxfmt":"^0.73.0","oxlint":"^1.88.0","tsdown":"^0.23.1","vitest":"^5.0.5","typescript":"^6.0.3","@vitest/coverage-v8":"^5.0.5","@arethetypeswrong/core":"^0.18.5"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/json-schema_3.0.0_1792139662417_0.04101974126866659"},"readme":"<h1 align=\"center\">\n  @peculiar/json-schema\n</h1>\n\n<div align=\"center\">\n\n![NPM License](https://img.shields.io/npm/l/@peculiar/json-schema)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/PeculiarVentures/json-schema/publish.yml?branch=master&label=publish)\n[![npm version](https://img.shields.io/npm/v/@peculiar/json-schema.svg)](https://www.npmjs.com/package/@peculiar/json-schema)\n![Coveralls](https://img.shields.io/coverallsCoverage/github/PeculiarVentures/json-schema)\n[![npm downloads](https://img.shields.io/npm/dm/@peculiar/json-schema.svg)](https://www.npmjs.com/package/@peculiar/json-schema)\n\n</div>\n\nSerialize and parse JSON with TypeScript classes. Describe the schema once with the `@JsonProp` decorator, and the library maps property names, converts values and validates input in both directions.\n\n## Introduction\n\nJSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write, but in practice it is a [minefield](https://seriot.ch/projects/parsing_json.html) when machines need to parse it.\n\nSchemas help, but they can be complicated to use. `@peculiar/json-schema` addresses this with decorators: you annotate a class, and the library handles serialization, parsing and validation of JSON for you.\n\nAll input data is untrusted, so it should be validated before use. Parsing into a schema gives you a typed object or a descriptive error.\n\n## Installation\n\n```sh\nnpm install @peculiar/json-schema\n```\n\nThe package is ESM-only with TypeScript declarations, and requires Node.js `^20.19.0 || >=22.12.0`. CommonJS code can still `require()` it on those versions.\n\n`@JsonProp` is a TypeScript legacy (experimental) decorator. Enable it in your `tsconfig.json`:\n\n```json\n{\n  \"compilerOptions\": {\n    \"experimentalDecorators\": true\n  }\n}\n```\n\n## Breaking Changes In v3\n\nv3 ships ESM only. The CommonJS build is removed: v2 published `build/index.js` (CommonJS), `build/index.mjs` (ESM) and `build/index.d.mts`; v3 publishes ES modules only, with `build/index.js` and `build/index.d.ts` as the entry point behind an `exports` map. The other files under `build/` mirror `src/` and are internal.\n\n- **Node.js `^20.19.0 || >=22.12.0` is required** (previously `>=16.0.0`). These versions support `require()` of ES modules, so CommonJS code can keep using `require(\"@peculiar/json-schema\")` without changes. Node.js 22.0–22.11 is not supported: it can't `require()` ESM.\n- **TypeScript projects that compile to CommonJS** need `\"module\": \"node20\"` or `\"nodenext\"` (TypeScript 5.9+). With `\"module\": \"node16\"` the compiler reports TS1479.\n- **ESM and bundler setups** (`\"module\": \"preserve\"`, `\"moduleResolution\": \"bundler\"`) work without changes.\n- **Legacy `\"moduleResolution\": \"node\"` (node10)** resolves the package through `types`; `@peculiar/json-schema` has no subpath exports, so nothing else changes.\n- **Jest in CommonJS mode** can't load ESM packages. Use Jest's ESM mode, add `@peculiar/json-schema` to the `transformIgnorePatterns` exceptions, or switch to Vitest.\n- **Deep imports stay blocked.** The `exports` map allows only `@peculiar/json-schema` and `@peculiar/json-schema/package.json`, as in v2.\n- **Internal types are no longer exported.** The bundled v2 declarations accidentally exposed `IJsonSchema`, `IJsonSchemaItem`, `IJsonNamedSchema` and `JsonTransform` as types. v3 exports the same 18 names as v1 and `src/index.ts`; type imports of those four no longer compile.\n- **`require()` and `import` share one schema storage.** v2 shipped separate CommonJS and ESM copies, so an application that loaded both (for example ESM code plus a CommonJS dependency) got two schema storages, and classes decorated through one copy were unknown to `JsonParser`/`JsonSerializer` from the other. v3 has a single module, so both load the same storage.\n\nApart from those four internal types, the public API is unchanged; only packaging and runtime requirements changed. `@JsonProp` still needs `\"experimentalDecorators\": true`.\n\n## Examples\n\n### Creating a schema\n\n```ts\nimport { JsonParser, JsonSerializer, JsonProp, JsonPropTypes, type IJsonConverter } from \"@peculiar/json-schema\";\n\n// Custom data converter\nconst JsonBase64UrlConverter: IJsonConverter<Uint8Array, string> = {\n  fromJSON: (value: string) => base64UrlToBuffer(value),\n  toJSON: (value: Uint8Array) => bufferToBase64Url(value),\n};\n\nclass EcPublicKey {\n  @JsonProp({ name: \"kty\" })\n  keyType = \"EC\";\n\n  @JsonProp({ name: \"crv\" })\n  namedCurve = \"\";\n\n  @JsonProp({ converter: JsonBase64UrlConverter })\n  x = new Uint8Array(0);\n\n  @JsonProp({ converter: JsonBase64UrlConverter })\n  y = new Uint8Array(0);\n\n  @JsonProp({ name: \"ext\", type: JsonPropTypes.Boolean, optional: true })\n  extractable = false;\n\n  @JsonProp({ name: \"key_ops\", type: JsonPropTypes.String, repeated: true, optional: true })\n  usages: string[] = [];\n}\n\nconst json = `{\n  \"kty\": \"EC\",\n  \"crv\": \"P-256\",\n  \"x\": \"zCQ5BPHPCLZYgdpo1n-x_90P2Ij52d53YVwTh3ZdiMo\",\n  \"y\": \"pDfQTUx0-OiZc5ZuKMcA7v2Q7ZPKsQwzB58bft0JTko\",\n  \"ext\": true\n}`;\n\nconst ecPubKey = JsonParser.parse(json, { targetSchema: EcPublicKey });\nconsole.log(ecPubKey);\n\necPubKey.usages.push(\"verify\");\n\nconst jsonText = JsonSerializer.serialize(ecPubKey, undefined, undefined, 2);\nconsole.log(jsonText);\n\n// Output\n//\n// EcPublicKey {keyType: \"EC\", namedCurve: \"P-256\", x: Uint8Array(32), y: Uint8Array(32), extractable: true, …}\n//\n// {\n//   \"kty\": \"EC\",\n//   \"crv\": \"P-256\",\n//   \"x\": \"zCQ5BPHPCLZYgdpo1n-x_90P2Ij52d53YVwTh3ZdiMo\",\n//   \"y\": \"pDfQTUx0-OiZc5ZuKMcA7v2Q7ZPKsQwzB58bft0JTko\",\n//   \"ext\": true,\n//   \"key_ops\": [\n//     \"verify\"\n//   ]\n// }\n```\n\n`base64UrlToBuffer` and `bufferToBase64Url` stand for any base64url helpers, such as `Buffer.from(value, \"base64url\")` in Node.js.\n\n### Extending a schema\n\n```ts\nimport { JsonParser, JsonSerializer, JsonProp } from \"@peculiar/json-schema\";\n\nclass BaseObject {\n  @JsonProp({ name: \"i\" })\n  public id = 0;\n}\n\nclass Word extends BaseObject {\n  @JsonProp({ name: \"t\" })\n  public text = \"\";\n}\n\nclass Person extends BaseObject {\n  @JsonProp({ name: \"n\" })\n  public name = \"\";\n\n  @JsonProp({ name: \"w\", repeated: true, type: Word })\n  public words: Word[] = [];\n}\n\nconst json = `{\n  \"i\": 1,\n  \"n\": \"Bob\",\n  \"w\": [\n    { \"i\": 2, \"t\": \"hello\" },\n    { \"i\": 3, \"t\": \"world\" }\n  ]\n}`;\n\nconst person = JsonParser.parse(json, { targetSchema: Person });\nconsole.log(person);\n\nconst word = new Word();\nword.id = 4;\nword.text = \"!!!\";\nperson.words.push(word);\n\nconst jsonText = JsonSerializer.serialize(person, undefined, undefined, 2);\nconsole.log(jsonText);\n\n// Output\n//\n// Person {id: 1, name: \"Bob\", words: [Word {id: 2, text: \"hello\"}, Word {id: 3, text: \"world\"}]}\n//\n// {\n//   \"i\": 1,\n//   \"n\": \"Bob\",\n//   \"w\": [\n//     {\n//       \"i\": 2,\n//       \"t\": \"hello\"\n//     },\n//     {\n//       \"i\": 3,\n//       \"t\": \"world\"\n//     },\n//     {\n//       \"i\": 4,\n//       \"t\": \"!!!\"\n//     }\n//   ]\n// }\n```\n\n## API\n\nSee the type declarations in [`src/index.ts`](src/index.ts) (published as `build/index.d.ts`).\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, commit conventions and the release flow.\n","publish_time":1792139662507,"_cnpm_publish_time":1792139662507,"dist-tags":{"latest":"3.0.0"}}