json-patch

RFC 6902 JSON Patch implementation


Keywords
library, data, d, json, json-patch
License
BSL-1.0
Install
dub fetch json-patch --version 0.0.1

Documentation

Build Status codecov license

JavaScript Object Notation (JSON) Patch

This is implementation of rfc6902.

JSON Patch defines a JSON document structure for expressing a sequence of operations to apply to a JavaScript Object Notation (JSON) document.

library functionality:

  • generate diff between two documents
  • patch in place document using generated patch

Json document format accepted: JSONValue

Interface

	alias JsonItem = JSONValue;
    
	// diff part
	DiffOperation[] diff(const ref JsonItem source, const ref JsonItem target,
                           const string path = "");

	JsonItem toJson(DiffOperation[] d);
	
	// patch part
	
	bool patchInPlace(ref JsonItem document, ref const JsonItem patch);

Usage

	import vision.json.patch.commons;
	import vision.json.patch.diff;
	import vision.json.patch.patch;
    
	JsonItem source = ...;
	JsonItem target = ...;
		
	auto patch = diff(source, target).toJson;
		
	auto patched = source;
	patched.patchInPlace(patch);
		
	assert(patched == target)