All Projects → wbish → Jsondiffpatch.net

wbish / Jsondiffpatch.net

Licence: mit
JSON object diffs and reversible patching (jsondiffpatch compatible)

Labels

Projects that are alternatives of or similar to Jsondiffpatch.net

Python Patch
Library to parse and apply unified diffs
Stars: ✭ 65 (-67.17%)
Mutual labels:  patch
Macos Patcher
Command line tool for running macOS on unsupported Macs
Stars: ✭ 114 (-42.42%)
Mutual labels:  patch
Astor
Automatic program repair for Java with generate-and-validate techniques ✌️✌️: jGenProg (2014) - jMutRepair (2016) - jKali (2016) - DeepRepair (2017) - Cardumen (2018) - 3sfix (2018)
Stars: ✭ 152 (-23.23%)
Mutual labels:  patch
Free Sidecar
Enable Sidecar on Unsupported iPads and Macs running iPadOS 13 and macOS Catalina
Stars: ✭ 1,159 (+485.35%)
Mutual labels:  patch
Patchy
⚓️ Patch the inner source of python functions at runtime.
Stars: ✭ 84 (-57.58%)
Mutual labels:  patch
Axbaseplugin
Android Plugin Framework
Stars: ✭ 122 (-38.38%)
Mutual labels:  patch
Tr2main
Tomb Raider II Injector Dynamic Library
Stars: ✭ 46 (-76.77%)
Mutual labels:  patch
Uksm
Ultra Kernel Samepage Merging
Stars: ✭ 176 (-11.11%)
Mutual labels:  patch
Facebook ssl pinning
Bypassing SSL Pinning in Facebook Android App
Stars: ✭ 95 (-52.02%)
Mutual labels:  patch
Wsus package publisher
Publish third-party applications into your WSUS.
Stars: ✭ 143 (-27.78%)
Mutual labels:  patch
Nightpatch
Enable Night Shift on any old Mac models.
Stars: ✭ 72 (-63.64%)
Mutual labels:  patch
Unityandroidhotupdate
(Unity3D热更新) provide a way to hot update Unity app on Android, support code&resources, not need lua js or IL runtime etc..., will not disturb your project development; just loading the new version apk file to achieve.
Stars: ✭ 85 (-57.07%)
Mutual labels:  patch
Patchfluent
💧 🦄 Customize Windows 10 Updates
Stars: ✭ 128 (-35.35%)
Mutual labels:  patch
Revokemsgpatcher
A hex editor for WeChat/QQ/TIM - PC版微信/QQ/TIM防撤回补丁(我已经看到了,撤回也没用了)
Stars: ✭ 12,482 (+6204.04%)
Mutual labels:  patch
Iterm2 Borderless
Borderless iTerm2 patch with a few extra features
Stars: ✭ 165 (-16.67%)
Mutual labels:  patch
Rad Studio Xe 10.3 Windows
RADStudio XE 10.3.3 Rio - Activation & Documentation
Stars: ✭ 63 (-68.18%)
Mutual labels:  patch
Apkdiffpatch
a C++ library and command-line tools for Zip(Jar,Apk) file Diff & Patch; create minimal delta/differential; support Jar sign(apk v1 sign) & apk v2,v3 sign .
Stars: ✭ 121 (-38.89%)
Mutual labels:  patch
Wasmpatch
🧱Yet Another Patch Module for iOS/macOS via WebAssembly
Stars: ✭ 192 (-3.03%)
Mutual labels:  patch
Patchman
Patchman is a Linux Patch Status Monitoring System
Stars: ✭ 163 (-17.68%)
Mutual labels:  patch
Binch
A light ELF binary patch tool in python urwid
Stars: ✭ 139 (-29.8%)
Mutual labels:  patch

jsondiffpatch.net

Build status NuGet

JSON object diffs and reversible patching (jsondiffpatch compatible)

Installing

Install from jsondiffpatch.net nuget website, or run the following command:

Install-Package JsonDiffPatch.Net

Usage

The library has support for the following 3 operations: Diff, Patch and Unpatch.

Diff

Diff two json objects

  var jdp = new JsonDiffPatch();
  var left = JToken.Parse(@"{ ""key"": false }");
  var right = JToken.Parse(@"{ ""key"": true }");

  JToken patch = jdp.Diff(left, right);

  Console.WriteLine(patch.ToString());

  // Output:
  // {
  //     "key": [false, true]
  // }

Patch

Patch a left object with a patch document

  var jdp = new JsonDiffPatch();
  var left = JToken.Parse(@"{ ""key"": false }");
  var right = JToken.Parse(@"{ ""key"": true }");
  JToken patch = jdp.Diff(left, right);

  var output = jdp.Patch(left, patch);

  Console.WriteLine(output.ToString());

  // Output:
  // {
  //     "key": true
  // }

Unpatch

Unpatch a right object with a patch document

  var jdp = new JsonDiffPatch();
  var left = JToken.Parse(@"{ ""key"": false }");
  var right = JToken.Parse(@"{ ""key"": true }");
  JToken patch = jdp.Diff(left, right);

  var output = jdp.Unpatch(right, patch);

  Console.WriteLine(output.ToString());

  // Output:
  // {
  //     "key": false
  // }

Advanced Usage

JsonDiffPatch.Net is designed to handle complex diffs by producing a compact diff object with enough information to patch and unpatch relevant JSON objects. The following are some of the most common cases you may hit when generating a diff:

  • Adding, Removing a property from an object
  • Changing the property value or even value type
  • Inserting and shifting elements in an array
  • Efficient string diffing using google-diff-match-patch
  • Nested object diffs

The full JSON patch document format is documented at https://github.com/benjamine/jsondiffpatch.

var left =
{
  "id": 100,
  "revision": 5,
  "items": [
    "car",
    "bus"
  ],
  "tagline": "I can't do it. This text is too long for me to handle! Please help me JsonDiffPatch!",
  "author": "wbish"
}

var right =
{
  "id": 100,
  "revision": 6,
  "items": [
    "bike",
    "bus",
    "car"
  ],
  "tagline": "I can do it. This text is not too long. Thanks JsonDiffPatch!",
  "author": {
    "first": "w",
    "last": "bish"
  }
}

var jdp = new JsonDiffPatch();
var output = jdp.Diff(left, right);

// Output:
{
  "revision": [   // Changed the value of a property
    5,            // Old value
    6             // New value
  ],
  "items": {      // Inserted and moved items in an array
    "0": [
      "bike"
    ],
    "_t": "a",
    "_1": [
      "",
      1,
      3
    ]
  },
  "tagline": [    // A long string diff using google-diff-match-patch
    "@@ -2,10 +2,8 @@\n  can\n-'t\n  do \[email protected]@ -23,49 +23,28 @@\n  is \n+not \n too long\n- for me to handle! Please help me\n+. Thanks\n  Jso\n",
    0,
    2
  ],
  "author": [     // Changed the type of the author property from string to object
    "wbish",
    {
      "first": "w",
      "last": "bish"
    }
  ]
}

JSON Patches (RFC 6902)

A diff result can be converted into JSON patches, according to the RFC 6902 spec.

var left = JObject.Parse("{ \"name\": \"Justin\" }");
var right = JObject.Parse("{ \"name\" : \"John\", \"age\": 34 }");
var patch = new JsonDiffPatch().Diff(left, right);
var formatter = new JsonDeltaFormatter();
var operations = formatter.Format(patch);

/*
operations: [
  { "op": "replace", "path": "/name", "value": "John" },
  { "op": "add", "path": "/age", "value": 34 }
]
*/

Attributions

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].