This post shares a small set of custom functions which make it easy to return results from ExecuteSQL as well-formed JSON.
- The functions require v.16 of FMP or later
- The functions are designed with performance in mind, and do not involve iterating over every row in the SQL result set.
- The sample file comes with a set of examples for both basic and advanced usage
- The sample file also contains a set of test cases which I have used over the years to ensure quality.
- The examples are crafted both to illustrate common usage, as well as to encourage readable code structure.
Several years ago, both for development use, and also as a hobby, I wrote a variety of custom functions that were related to using JSON within FileMaker. Of all of these functions, the ones that I still use to this day, even on a weekly basis, are the ones shared here in this post, which allow for returning ExecuteSQL results as JSON.
I have not attempted to aggressively share these functions, because, under the hood, the code is somewhat involved, and I have wanted to respect the general sentiment that I think most of us have, which is that we prefer to only utilize code which we can easily grok and understand. Moreover, with the recent addition of the Execute Data API script step, FileMaker devs now have another easy way to retrieve table data as JSON, and with that, I imagined there would be a decreased demand for something like these functions.
Nonetheless, I periodically receive requests for these functions, either from YouTube viewers, or members of the Claris-based forum, or even some who have contacted me here at The Soup. Thus, this morning I decided to share the functions here at The Soup, having just recently noticed that the Resources section of this site might be an appropriate place to share.
These functions are now 3-4 years old, and have benefited from the suggestions, input, and occasional bug reports from friends and colleagues, as well as my own use. I hope others may enjoy them. They are free to use and distribute. I have done my best to keep them at a tip-top high level of quality, but even so, they come with no guarantees.
The basic ideas behind how these functions work/behave are documented in a couple of YouTube videos:
- ExecuteSQL To JSON - Part 01 [Escaping Values] - YouTube
- ExecuteSQL To JSON - Part 02 [Custom Function Approach] - YouTube
Please feel free to reach out to me about them, should you have any questions, etc.
Below are a few screenshots of the sample file, followed by the sample file, itself.
Thanks for reading, and best regards.
- SQL_JSON_Demo_20210814_1310.fmp12.zip (821.7 KB)