Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron Ruth committed Oct 15, 2011
0 parents commit d7709d4
Show file tree
Hide file tree
Showing 7 changed files with 2,766 additions and 0 deletions.
51 changes: 51 additions & 0 deletions README.md
@@ -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}]);
```
20 changes: 20 additions & 0 deletions index.html
@@ -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>

0 comments on commit d7709d4

Please sign in to comment.