fast-json-patch
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Fast-json-patch is a lean and high-performing implementation of JSON Patch (RFC-6902) that offers duplex capabilities. It allows you to apply patches or arrays/single operations to a JavaScript object, validate a sequence of patches, observe changes and generate patches when a change is detected, and compare two objects to obtain the difference. Fast-json-patch provides a judicious way to update a JSON document by sending the changes instead of the whole document, thus making it more efficient and reliable for HTTP PATCH verb and REST style programming.
To use fast-json-patch, first, you need to install it in your project with npm:
npm install fast-json-patch --save
In a web browser, load the bundled distribution script:
<script src="dist/fast-json-patch.min.js"></script>
In Node.js, you can use fast-json-patch as an ECMAScript module:
import * as jsonpatch from 'fast-json-patch/index.mjs';
import { applyOperation } from 'fast-json-patch/index.mjs';
Or with the older CommonJS syntax:
const { applyOperation } = require('fast-json-patch');
const applyOperation = require('fast-json-patch').applyOperation;
You can then begin to apply patches. For example:
var document = { firstName: "Albert", contactDetails: { phoneNumbers: [] } };
var patch = [
{ op: "replace", path: "/firstName", value: "Joachim" },
{ op: "add", path: "/lastName", value: "Wester" },
{ op: "add", path: "/contactDetails/phoneNumbers/0", value: { number: "555-123" } }
];
document = jsonpatch.applyPatch(document, patch).newDocument;
The fast-json-patch documentation is included in the README content of the package. To access in-depth details about the fast-json-patch API and its features, you can reference this readme file on the fast-json-patch GitHub page.