I want to use the "fast-json-patch" library (https://github.com/Starcounter-Jack/JSON-Patch) in an Angular 2 application.
I have tried adding:
'fast-json-patch': 'vendor/fast-json-patch/dist/json-patch-duplex.min.js'
in the system-config.ts
file under the map
but it doesn't work when importing fast-json-patch
RFC 6902: JavaScript Object Notation (JSON) Patch.
How it works. A JSON Patch document is just a JSON file containing an array of patch operations. The patch operations supported by JSON Patch are “add”, “remove”, “replace”, “move”, “copy” and “test”. The operations are applied in order: if any of them fail then the whole patch operation should abort.
JSON Patch is a web standard format for describing changes in a JSON document. It is meant to be used together with HTTP Patch which allows for the modification of existing HTTP resources. The JSON Patch media type is application/json-patch+json . JSON Patch. Filename extension.
A JSON merge patch document describes changes to be made to a target JSON document using a syntax that closely mimics the document being modified.
1) Install the package
npm install fast-json-patch --save
2) In the component, where you want to use ist, import the functions you need:
import { compare } from 'fast-json-patch';
3) To create a Patch compare the old object with the new object:
const patch = compare(oldObj, modifiedObj);
4) Print out the result:
console.log(patch);
0:{op: "replace", path: "/firmendetails/registergericht", value: "Darmstadt xx"}
1:{op: "remove", path: "/firmendetails/handelsname"}
2:{op: "remove", path: "/firmendetails/firma"}
3:{op: "remove", path: "/firmendetails/rechtsform"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With