Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
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 |
Parameter | Description | Example | Flags |
---|---|---|---|
json1 | A JSON text or reference. | ||
json2 | A JSON text or reference. | ||
KeyToCopy | Available in MBS FileMaker Plugin 14.1 or newer. When we create our change record, we can optionally carry over an extra field for the changes. |
"pkey" | Optional |
Returns JSON or error.
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"
}
]
This function checks for a license.
Created 23th November 2023, last changed 31st January 2024