Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
JSON.JSONPatch.FromDiff
Create a JSON Patch from a diff of two json documents.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
JSON | 14.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
json1 | A JSON text or reference. | ||
json2 | A JSON text or reference. | ||
KeyToCopy | When we create our change record, we can optionally carry over an extra field for the changes. | "pkey" | Optional Added in version 14.1. |
Result
Returns JSON or error.
Description
Create a JSON Patch from a diff of two json documents.Returns a JSON Patch.
The jsonpatch functions implement the IETF standard JavaScript Object Notation (JSON) Patch.
The JSON Patch IETF standard requires that the JSON Patch method is atomic, so that if any JSON Patch operation results in an error, the target document is unchanged. The patch function implements this requirement by generating the inverse commands and building an undo stack, which is executed if any part of the patch fails.
Use JSON.JSONPatch.ApplyPatch to apply the patch to JSON data later.
Examples
Create a patch:
MBS( "JSON.JSONPatch.FromDiff";
"{\"people\":[{\"first\":\"Christian\",\"last\":\"Miller\",\"city\":\"Nickenich\"}]}";
"{\"people\":[{\"first\":\"Peter\",\"city\":\"Nickenich\", \"zip\": 56645 }]}" )
Example result:
[
{
"op": "replace",
"path": "/people/0/first",
"value": "Peter"
},
{
"op": "remove",
"path": "/people/0/last"
},
{
"op": "add",
"path": "/people/0/zip",
"value": 56645
}
]
Try with additional key to copy:
Let ( [
json1 = "{\"people\":[{\"first\":\"Christian\",\"last\":\"Miller\",\"city\":\"Nickenich\",\"pkey\":\"EAE6757654564DEAC\"}]}";
json2 = "{\"people\":[{\"first\":\"Peter\",\"city\":\"Nickenich\", \"zip\": 56645, \"pkey\":\"EAE6757654564DEAC\" }]}";
patch = MBS( "JSON.JSONPatch.FromDiff"; json1; json2; "pkey" )]; patch )
Example result:
[
{
"op": "replace",
"path": "/people/0/first",
"value": "Peter",
"pkey": "EAE6757654564DEAC"
},
{
"op": "remove",
"path": "/people/0/last",
"pkey": "EAE6757654564DEAC"
},
{
"op": "add",
"path": "/people/0/zip",
"value": 56645,
"pkey": "EAE6757654564DEAC"
}
]
See also
Release notes
- Version 15.3
- Fixed JSON.JSONPatch.FromDiff to do the copy key feature again, broken with jsoncons update in version 15.1.
- Version 14.1
- Added KeyToCopy parameter to JSON.JSONPatch.FromDiff to copy primary keys.
- Version 14.0
- Added JSON.JSONPatch.ApplyPatch, JSON.JSONPatch.FromDiff, JSON.MergePatch.ApplyPatch and JSON.MergePatch.FromDiff functions.
Blog Entries
- MBS FileMaker Plugin, version 15.3pr2
- Neues MBS Plugin 14.1 für Claris FileMaker
- MBS Plugin 14.1 for Claris FileMaker
- MBS FileMaker Plugin, version 14.1pr1
- New in MBS FileMaker Plugin 14.0
- MBS @ FMTraining.TV - FileMaker Monkeybread Plug-in Q&A
- MBS FileMaker Plugin, version 13.6pr1
This function checks for a license.
Created 23th November 2023, last changed 31st January 2024
