Custom function for calculating diffs/deltas between JSON Objects

Document created by steve_ssh on Oct 8, 2018Last modified by steve_ssh on Oct 9, 2018
Version 5Show Document
  • View in full screen mode



This document is home to a Custom Function which calculates and returns the value differences between two JSON dictionaries.


I realize that many developers might prefer another method for calculating such a "JSON diff", and, in many cases with good reason.


That said, I include the function here for others to use, should it meet their needs.


The function, and details regarding usage, nuances, and limitations can be found in a sample file which should be attached to this document.


Thank you very much for taking a look.



The function parameters include two blocks of JSON to compare, and various flags to determine the output format:


cf signature.png


Trivial sample input to illustrate some of the possible output formats:


sample input.png



A basic output format which lists the "deltas" between the two input dictionaries:


output 01.png



A variant on the output format, which groups the delta entries by type:


output 02.png



Another output variant, which organizes the delta objects by Key:


output 03.png



Output can optionally include meta-data which includes counts of the various delta types:


output 04.png



Output data can optionally include delta objects which record unchanged values:


output 05.png



An optional "depth" parameter allows the function to calculate and return deltas for nested children:


output 06.png



(All of the above output formats are determined by parameters passed into the function.)



A 10-minute introduction to this custom function:







This function came about during a personal study that I started about a week or two ago, where I was experimenting with various structural approaches to authoring recursive custom functions of above-average complexity.  Since v.16 of FileMaker, my approach to writing some recursive custom functions adapted to leverage the ability of being able to pass blocks of JSON between function iterations.  This had worked well for me in various cases, and I decided to experiment to see if I could formalize the approach that I was using, in order to make recursive function writing more palatable, more testable, and less challenging/daunting for other developers.


For this undertaking, I needed to choose a function task that would be within reach, and yet sufficiently complex so as to serve as a good test case for these approaches.  Given that I had been seeing increasing evidence that developers are taking JSON record "snapshots" for auditing and or sync purposes, I decided that a "diff" function for simple JSON dictionaries would be an adequate test case.


I wound up writing this function three times, using three different methodologies, comparing each for readability, performance, and debuggability.  As it turns out, none of the methodologies that I was hoping might be of use to others yielded results which I thought warranted sharing.  Thus, I have nothing new to share with respect to the writing of recursive functions.


Still, as a side-effect of having made this inquiry, I was left with a working "JSON dictionary-diff" function.  Knowing that the length of the function code would (understandably) be cause for concern to others, I considered leaving this one on the shelf without sharing it.  In the end, having first-hand knowledge of its construction, and believing that construction to be of reasonable quality, I decided to go ahead and post it here for any who are interested.  I hope some folks may enjoy it!


Kind regards,






Attachment History:

Date Uploaded
Archive NameCF VersionComment
08 October 2018, 09:05 PacificJSONDictionaryCompare_CF_V2_20181008_1738.fmp12.zip20181008_1602Initial Upload
09 October 2018, 04:32 PacificJSONDictionaryCompare_CF_V2_20181009_1627.fmp12.zip20181009_1627Corrected bug where CF incorrectly returned an error for valid input containing certain combinations of escape sequences.
12 people found this helpful