FileMaker 18 Data API > Create Record - JSON visualization and building

FileMaker Pro 19 only required. Cool. Thanks.

I have heard reports that the JSONSetElement has to parse the JSON on each call and that the performance can slow down (in a nonlinear fashion?) as the JSON grows.

This is the a similar idea to using the List function and a stored field to build JSON from a list of records.

That said, I am not sure if using JSONSetElement vs. Text functions speed has been tested and reported conclusively.

The JSON that I am building is derived from 3 tables…a parent table and 2 child tables…one of which is in an external file.

Currently I am scripting from the parent file context and walking the 2 portals row by row and building up text line by line using the List function.

After the List is built, a substitute is applied and the text is wrapped with “{}“ or “[]“ to make it into a JSON Object or Array respectively.

On the next line, I use the JSONFormatElements for debugging, and to make sure that the JSON is valid. These JSONFormatElements lines could be turn off later when everything is tested as working

There are 3 pieces to the final JSON: 1 fieldData Object and 2 portalData Arrays.

All three of these are built separately and then combined. This is more modular and seems likely to be faster.

The fieldData object is built in a single call to JSONSetElement, using the [] syntax, which I hope (and expect) requires 1 or 0 parsing operations (as I am targeting an empty object).

The 2 arrays are built up using text functions as I have heard this method might be faster.

Each line is built using a Custom Function that produces the Key and the JSON encoded Value.

After the the List is built, a Substitute is applied and the text is wrapped with a “[]“ to make it into a JSON Array.

Finally the 1 JSON Object and 2 JSON Arrays are combined into a single JSON Object using a single call to the JSONSetElement:

JSONSetElement ( "{}" ; 
[ "fieldData" ; $fieldData.obj ; JSONObject ] ;
[ "portalData" ; "" ; JSONObject ] ;
[ "portalData.Inspection___Inspect_Line__id" ; $portalData.Inspection___Inspect_Line__id.array ; JSONArray ] ;
[ "portalData.Inspection___InspectCode__code" ; $portalData.Inspection___InspectCode__code.array ; JSONArray ]
)

Text functions vs JSONSetElement?

I am not sure how many rows there would have to be before there would be a performance difference.

Might be a case of premature optimization?

Any hard numbers out there?