Skip to content

Instantly share code, notes, and snippets.

@briancavalier
Created July 9, 2014 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briancavalier/7f2f90b9d5efb56e86a5 to your computer and use it in GitHub Desktop.
Save briancavalier/7f2f90b9d5efb56e86a5 to your computer and use it in GitHub Desktop.
// JSON Patch containing a splice operation with context
[{
"op": "splice",
"path": "/3",
"+": ["d", "e"],
"-": ["x", "y", "z"],
"<": ["a", "b", "c"],
">": ["f", "g"]
}]
// Applied to this array:
["extra", "a", "b", "c", "x", "y", "z", "f", "g"]
// Yields:
["extra", "a", "b", "c", "d", "e", "f", "g"]
// Inverting a splice, simply swap + and -
[{
"op": "splice",
"path": "/3",
"+": ["x", "y", "z"],
"-": ["d", "e"],
"<": ["a", "b", "c"],
">": ["f", "g"]
}]
// Applied to the previous result:
["extra", "a", "b", "c", "d", "e", "f", "g"]
// Yields the original:
["extra", "a", "b", "c", "x", "y", "z", "f", "g"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment