New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json-merge-patch

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-merge-patch

Implementation of JSON Merge Patch (RFC 7396)

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
158K
increased by5.02%
Maintainers
1
Weekly downloads
 
Created

What is json-merge-patch?

The json-merge-patch npm package allows you to apply RFC 7396 JSON Merge Patch operations to JSON documents. This is useful for updating JSON objects by merging changes rather than replacing entire objects.

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

Merging JSON Objects

This feature allows you to merge two JSON objects. The `apply` method takes a target object and a patch object, and returns a new object that is the result of applying the patch to the target.

const jsonMergePatch = require('json-merge-patch');

const target = { a: 1, b: 2 };
const patch = { b: 3, c: 4 };
const result = jsonMergePatch.apply(target, patch);
console.log(result); // { a: 1, b: 3, c: 4 }

Removing Properties

This feature allows you to remove properties from a JSON object by setting their values to `null` in the patch object. The `apply` method will remove the property from the target object.

const jsonMergePatch = require('json-merge-patch');

const target = { a: 1, b: 2, c: 3 };
const patch = { b: null };
const result = jsonMergePatch.apply(target, patch);
console.log(result); // { a: 1, c: 3 }

Nested Merging

This feature allows you to merge nested JSON objects. The `apply` method will recursively merge nested objects, updating only the specified properties.

const jsonMergePatch = require('json-merge-patch');

const target = { a: { b: 1, c: 2 } };
const patch = { a: { c: 3, d: 4 } };
const result = jsonMergePatch.apply(target, patch);
console.log(result); // { a: { b: 1, c: 3, d: 4 } }

Other packages similar to json-merge-patch

Keywords

FAQs

Package last updated on 21 Jul 2021

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