This package (`json-patch-test-suite`) serves as the official and community-maintained collection of test cases designed to validate implementations of the IETF JSON Patch specification (RFC 6902). It does not provide an actual JSON Patch implementation, but rather offers a standardized data set comprising source documents, applicable patches, and either the expected resulting document or a description of an anticipated error. The current stable version is 1.1.0. As a static test suite for a well-established RFC, its release cadence is infrequent, primarily occurring when new edge cases are identified or the RFC itself undergoes revisions. Its primary value lies in offering a neutral, comprehensive, and widely-adopted benchmark that allows developers to rigorously test their JSON Patch libraries for strict conformance to the RFC 6902 standard, ensuring interoperability and correctness across various programming languages and environments. This helps to prevent divergent interpretations of the specification.
npm install json-patch-test-suiteVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load the `tests.json` file from the `json-patch-test-suite` package and iterate through each test record. It shows how to integrate the test data with a hypothetical `applyPatch` function (which you would replace with your actual JSON Patch implementation) to validate its behavior against the suite's expected outcomes or errors. The example uses Node.js `fs` and `path` for file loading.
For TypeScript projects, ensure `"resolveJsonModule": true` and `"esModuleInterop": true` are set in your `tsconfig.json`'s `compilerOptions`. When using bundlers (e.g., Webpack, Rollup, Parcel), verify they are configured to handle JSON file imports (often built-in). For Node.js ESM, ensure your `package.json` specifies `"type": "module"` or use `.mjs` files for ESM modules.
JSON Patch implementations may produce varying error messages. When `test.error` is present, focus on verifying that *an* error is thrown by your patching logic, rather than performing a strict string equality comparison against the `test.error` value. You might check for the *type* of error or a partial match for robustness.
Developers must integrate this test suite with their own JSON Patch library (e.g., `fast-json-patch`, `json-patch-js`) to actually apply the patches and validate the results. The quickstart example illustrates how to provide a placeholder `applyPatch` function that you would replace with your library's actual function.
For TypeScript, add `"resolveJsonModule": true` and `"esModuleInterop": true` to the `compilerOptions` in your `tsconfig.json`. If using a bundler (like Webpack), ensure your configuration includes a JSON loader (often enabled by default). Double-check the exact import path: `import tests from 'json-patch-test-suite/tests.json'`.
Ensure that your `require()` call explicitly targets the `.json` file extension (e.g., `const tests = require('json-patch-test-suite/tests.json')`). If using ESM in Node.js, confirm your `package.json` contains `"type": "module"` or use the `.mjs` extension for your module files, and configure your bundler/TypeScript to resolve JSON modules.No dependency data recorded yet.