Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Byron Ruth
committed
Oct 15, 2011
0 parents
commit d7709d4
Showing
7 changed files
with
2,766 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
jsonpatch.js | ||
============ | ||
Library to apply JSON Patches in JavaScript | ||
http://tools.ietf.org/html/draft-pbryan-json-patch-01 | ||
|
||
Note: all operations are applied in-place. | ||
|
||
Add | ||
--- | ||
Patch syntax: ``{add: <path>, value: <value>}`` | ||
|
||
```javascript | ||
// Add property, result: {foo: 'bar'} | ||
jsonpatch.apply({}, [{add: '/foo', value: 'bar'}]); | ||
|
||
// Add array element, result: {foo: [1, 2, 3]} | ||
jsonpatch.apply({foo: [1, 3]}, [{add: '/foo/1', value: 2}]); | ||
|
||
// Complex, result: {foo: [{bar: 'baz'}]} | ||
jsonpatch.apply({foo: [{}]}, [{add: '/foo/0/bar', value: 'baz'}]); | ||
``` | ||
|
||
Remove | ||
------ | ||
Patch syntax: ``{remove: <path>}`` | ||
|
||
```javascript | ||
// Remove property, result: {} | ||
jsonpatch.apply({foo: 'bar'}, [{remove: '/foo'}]); | ||
|
||
// Remove array element, result: {foo: [1, 3]} | ||
jsonpatch.apply({foo: [1, 2, 3]}, [{remove: '/foo/1'}]); | ||
|
||
// Complex, result: {foo: [{}]} | ||
jsonpatch.apply({foo: [{bar: 'baz'}]}, [{remove: '/foo/0/bar'}]); | ||
``` | ||
|
||
Replace | ||
------ | ||
Patch syntax: ``{replace: <path>, value: <value>}`` | ||
|
||
```javascript | ||
// Replace property, result: {foo: 1} | ||
jsonpatch.apply({foo: 'bar'}, [{replace: '/foo', value: 1}]); | ||
|
||
// Repalce array element, result: {foo: [1, 4, 3]} | ||
jsonpatch.apply({foo: [1, 2, 3]}, [{replace: '/foo/1', value: 4}]); | ||
|
||
// Complex, result: {foo: [{bar: 1}]} | ||
jsonpatch.apply({foo: [{bar: 'baz'}]}, [{replace: '/foo/0/bar', value: 1}]); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>QUnit Test Suite</title> | ||
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen"> | ||
<script type="text/javascript" src="qunit.js"></script> | ||
<script type="text/javascript" src="jsonpatch.js"></script> | ||
<script type="text/javascript" src="jslitmus.js"></script> | ||
<script type="text/javascript" src="test.js"></script> | ||
</head> | ||
<body> | ||
<h1 id="qunit-header">QUnit Test Suite</h1> | ||
<h2 id="qunit-banner"></h2> | ||
<div id="qunit-testrunner-toolbar"></div> | ||
<h2 id="qunit-userAgent"></h2> | ||
<ol id="qunit-tests"></ol> | ||
<div id="qunit-fixture"></div> | ||
</body> | ||
</html> |
Oops, something went wrong.