Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-json-patch

Package Overview
Dependencies
Maintainers
3
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-json-patch

Fast implementation of JSON-Patch (RFC-6902) with duplex (observe changes) capabilities

  • 2.2.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is fast-json-patch?

The fast-json-patch package allows for the observation of changes to a JSON document, generating JSON Patch documents to capture these changes, and applying such patches to JSON documents. It is useful for efficiently synchronizing JSON data between clients and servers or among components of an application.

What are fast-json-patch's main functionalities?

Generating patches

This feature allows for the observation of a JSON document and the generation of a JSON Patch document representing the changes made to the observed document.

const jsonpatch = require('fast-json-patch');
const document = { firstName: 'Albert', contact: { phone: '123' } };
const observer = jsonpatch.observe(document);
document.firstName = 'Joachim';
document.contact.phone = '456';
const patches = jsonpatch.generate(observer);

Applying patches

This feature applies a JSON Patch document to a JSON document, modifying the target document according to the operations described in the patch.

const jsonpatch = require('fast-json-patch');
const document = { firstName: 'Albert', contact: { phone: '123' } };
const patches = [{ op: 'replace', path: '/firstName', value: 'Joachim' }, { op: 'replace', path: '/contact/phone', value: '456' }];
jsonpatch.applyPatch(document, patches);

Validating a sequence of operations

This feature validates a sequence of operations against a JSON document to ensure they can be applied without errors, providing a way to check patches for correctness before application.

const jsonpatch = require('fast-json-patch');
const document = { firstName: 'Albert', contact: { phone: '123' } };
const patches = [{ op: 'replace', path: '/firstName', value: 'Joachim' }, { op: 'add', path: '/lastName', value: 'Wagner' }];
const validationResult = jsonpatch.validate(patches, document);

Other packages similar to fast-json-patch

Keywords

FAQs

Package last updated on 09 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc